Unverified Commit aaa470ee authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3131348 by Spokje, jungle, mondrake, vsujeetkumar, sja112,...

Issue #3131348 by Spokje, jungle, mondrake, vsujeetkumar, sja112, kishor_kolekar, Hardik_Patel_12, mrinalini9, yogeshmpawar, daffie: Replace assertions involving calls to empty() with assertEmpty()/assertNotEmpty()/assertArrayNotHasKey()

(cherry picked from commit 09795b6e)
parent 3f59ee8a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ public function testfetch() {
    // Create feed with local url.
    $feed = $this->createFeed();
    $this->updateFeedItems($feed);
    $this->assertFalse(empty($feed->items));
    $this->assertNotEmpty($feed->items);

    // Delete items and restore checked property to 0.
    $this->deleteFeedItems($feed);
@@ -43,7 +43,7 @@ public function testfetch() {
    $feed->save();
    $this->updateFeedItems($feed);
    // Fetch should fail due to feed name.
    $this->assertTrue(empty($feed->items));
    $this->assertEmpty($feed->items);
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public function testDelete() {
    $this->updateAndDelete($feed, NULL);
    // Make sure the feed title is changed.
    $entities = \Drupal::entityTypeManager()->getStorage('aggregator_feed')->loadByProperties(['description' => $description]);
    $this->assertTrue(empty($entities));
    $this->assertEmpty($entities);
  }

  /**
+16 −3
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ public function testBigPipe() {
    $this->assertSession()->responseContains('</body>');

    // Verifying BigPipe assets are present.
    $this->assertFalse(empty($this->getDrupalSettings()), 'drupalSettings present.');
    $this->assertNotEmpty($this->getDrupalSettings());
    $this->assertContains('big_pipe/big_pipe', explode(',', $this->getDrupalSettings()['ajaxPageState']['libraries']), 'BigPipe asset library is present.');

    // Verify that the two expected exceptions are logged as errors.
@@ -506,12 +506,25 @@ protected function assertBigPipeNoJsMetaRefreshRedirect(): void {
    $this->assertEquals(302, $statuses[0], 'The first response was a 302 (redirect).');
    $this->assertStringStartsWith('big_pipe_nojs=1', $headers[0]['Set-Cookie'][0], 'The first response sets the big_pipe_nojs cookie.');
    $this->assertEquals($original_url, $headers[0]['Location'][0], 'The first response redirected back to the original page.');
    $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.');
    $this->assertEmpty(
      array_diff([
        'cookies:big_pipe_nojs',
        'session.exists',
      ], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0])),
      'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'
    );
    $this->assertFalse(isset($headers[0]['Surrogate-Control']), 'The first response has no "Surrogate-Control" header.');

    // Second response: redirect followed.
    $this->assertEquals(200, $statuses[1], 'The second response was a 200.');
    $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.');
    $this->assertEmpty(
      array_diff([
        'cookies:big_pipe_nojs',
        'session.exists',
      ], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0])),
      'The second response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'
    );

    $this->assertEquals('no-store, content="BigPipe/1.0"', $headers[1]['Surrogate-Control'][0], 'The second response has a "Surrogate-Control" header.');

    // Check that the <meta> refresh is absent, only one redirect ever happens.
+2 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\Tests\block\Functional;

use Drupal\block\Entity\Block;
use Drupal\Component\Render\FormattableMarkup;

/**
 * Provides test assertions for testing block appearance.
@@ -20,7 +19,7 @@ trait AssertBlockAppearsTrait {
   */
  protected function assertBlockAppears(Block $block) {
    $result = $this->findBlockInstance($block);
    $this->assertTrue(!empty($result), new FormattableMarkup('The block @id appears on the page', ['@id' => $block->id()]));
    $this->assertNotEmpty($result, sprintf('The block %s should appear on the page.', $block->id()));
  }

  /**
@@ -31,7 +30,7 @@ protected function assertBlockAppears(Block $block) {
   */
  protected function assertNoBlockAppears(Block $block) {
    $result = $this->findBlockInstance($block);
    $this->assertFalse(!empty($result), new FormattableMarkup('The block @id does not appear on the page', ['@id' => $block->id()]));
    $this->assertEmpty($result, sprintf('The block %s should not appear on the page.', $block->id()));
  }

  /**
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public function testHtml() {

    // Ensure expected markup for a menu block.
    $elements = $this->xpath('//nav[contains(@class, :nav-class)]/ul[contains(@class, :ul-class)]/li', [':nav-class' => 'block-menu', ':ul-class' => 'menu']);
    $this->assertTrue(!empty($elements), 'The proper block markup was found.');
    $this->assertNotEmpty($elements, 'The proper block markup was found.');
  }

}
Loading