Commit 3e0f0155 authored by catch's avatar catch
Browse files

Issue #3131186 by mondrake, Vidushi Mehta, longwave, paulocs, xjm: Replace...

Issue #3131186 by mondrake, Vidushi Mehta, longwave, paulocs, xjm: Replace assertions involving calls to drupalGetHeader() with session-based assertions, where possible
parent 1e06a3ef
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
@@ -68,18 +68,15 @@ public function testBlockLinks() {
    $href = $feed->toUrl()->toString();
    $links = $this->xpath('//a[@href = :href]', [':href' => $href]);
    $this->assert(isset($links[0]), new FormattableMarkup('Link to href %href found.', ['%href' => $href]));
    $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
    $cache_tags = explode(' ', $cache_tags_header);
    $this->assertContains('aggregator_feed:' . $feed->id(), $cache_tags);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());

    // Visit that page.
    $this->drupalGet($feed->toUrl()->getInternalPath());
    $correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', [':title' => $feed->label()]);
    $this->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.');
    $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
    $this->assertContains('aggregator_feed:' . $feed->id(), $cache_tags);
    $this->assertContains('aggregator_feed_view', $cache_tags);
    $this->assertContains('aggregator_item_view', $cache_tags);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed_view');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_item_view');

    // Set the number of news items to 0 to test that the block does not show
    // up.
@@ -120,9 +117,7 @@ public function testFeedPage() {
    $href = $feed->toUrl()->toString();
    $links = $this->xpath('//a[@href = :href]', [':href' => $href]);
    $this->assertTrue(isset($links[0]), new FormattableMarkup('Link to href %href found.', ['%href' => $href]));
    $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
    $cache_tags = explode(' ', $cache_tags_header);
    $this->assertContains('aggregator_feed:' . $feed->id(), $cache_tags);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());

    // Check the rss aggregator page as anonymous user.
    $this->drupalLogout();
@@ -133,7 +128,7 @@ public function testFeedPage() {
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('aggregator/rss');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertEqual($this->drupalGetHeader('Content-type'), 'application/rss+xml; charset=utf-8');
    $this->assertSession()->responseHeaderEquals('Content-Type', 'application/rss+xml; charset=utf-8');

    // Check the opml aggregator page.
    $this->drupalGet('aggregator/opml');
@@ -150,10 +145,9 @@ public function testFeedPage() {
    $this->drupalGet('aggregator/sources/' . $feed->id());
    $elements = $this->xpath("//ul[contains(@class, :class)]", [':class' => 'pager__items']);
    $this->assertTrue(!empty($elements), 'Individual source page contains a pager.');
    $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
    $this->assertContains('aggregator_feed:' . $feed->id(), $cache_tags);
    $this->assertContains('aggregator_feed_view', $cache_tags);
    $this->assertContains('aggregator_item_view', $cache_tags);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed_view');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_item_view');
  }

}
+4 −5
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\Tests\basic_auth\Functional;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Url;
use Drupal\Tests\basic_auth\Traits\BasicAuthTestTrait;
use Drupal\language\Entity\ConfigurableLanguage;
@@ -52,7 +51,7 @@ public function testBasicAuth() {
    $this->assertText($account->getAccountName(), 'Account name is displayed.');
    $this->assertSession()->statusCodeEquals(200);
    $this->mink->resetSessions();
    $this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
    // Check that Cache-Control is not set to public.
    $this->assertSession()->responseHeaderNotContains('Cache-Control', 'public');

@@ -65,7 +64,7 @@ public function testBasicAuth() {
    // Ensure that the user is prompted to authenticate if they are not yet
    // authenticated and the route only allows basic auth.
    $this->drupalGet($url);
    $this->assertEqual($this->drupalGetHeader('WWW-Authenticate'), new FormattableMarkup('Basic realm="@realm"', ['@realm' => \Drupal::config('system.site')->get('name')]));
    $this->assertSession()->responseHeaderEquals('WWW-Authenticate', 'Basic realm="' . \Drupal::config('system.site')->get('name') . '"');
    $this->assertSession()->statusCodeEquals(401);

    // Ensure that a route without basic auth defined doesn't prompt for auth.
@@ -84,9 +83,9 @@ public function testBasicAuth() {
    // cache if basic auth credentials are provided.
    $url = Url::fromRoute('router_test.10');
    $this->drupalGet($url);
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
    $this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);
    $this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
    // Check that Cache-Control is not set to public.
    $this->assertSession()->responseHeaderNotContains('Cache-Control', 'public');
  }
+3 −3
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ public function testBigPipeNoJs() {
    ]);

    // Verifying there are no BigPipe placeholders & replacements.
    $this->assertEqual('<none>', $this->drupalGetHeader('BigPipe-Test-Placeholders'));
    $this->assertSession()->responseHeaderEquals('BigPipe-Test-Placeholders', '<none>');
    // Verifying BigPipe start/stop signals are absent.
    $this->assertNoRaw(BigPipe::START_SIGNAL, 'BigPipe start signal absent.');
    $this->assertNoRaw(BigPipe::STOP_SIGNAL, 'BigPipe stop signal absent.');
@@ -327,8 +327,8 @@ public function testBigPipeMultiOccurrencePlaceholders() {
  protected function assertBigPipeResponseHeadersPresent() {
    // Check that Cache-Control header set to "private".
    $this->assertSession()->responseHeaderContains('Cache-Control', 'private');
    $this->assertEqual('no-store, content="BigPipe/1.0"', $this->drupalGetHeader('Surrogate-Control'));
    $this->assertEqual('no', $this->drupalGetHeader('X-Accel-Buffering'));
    $this->assertSession()->responseHeaderEquals('Surrogate-Control', 'no-store, content="BigPipe/1.0"');
    $this->assertSession()->responseHeaderEquals('X-Accel-Buffering', 'no');
  }

  /**
+8 −8
Original line number Diff line number Diff line
@@ -376,12 +376,12 @@ public function testBlockCacheTags() {

    // Prime the page cache.
    $this->drupalGet('<front>');
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');

    // Verify a cache hit, but also the presence of the correct cache tags in
    // both the page and block caches.
    $this->drupalGet('<front>');
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');
    $cid_parts = [Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), ''];
    $cid = implode(':', $cid_parts);
    $cache_entry = \Drupal::cache('page')->get($cid);
@@ -409,20 +409,20 @@ public function testBlockCacheTags() {
    $block->setRegion('content');
    $block->save();
    $this->drupalGet('<front>');
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');

    // Now we should have a cache hit again.
    $this->drupalGet('<front>');
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');

    // Place the "Powered by Drupal" block another time; verify a cache miss.
    $this->drupalPlaceBlock('system_powered_by_block', ['id' => 'powered-2']);
    $this->drupalGet('<front>');
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');

    // Verify a cache hit, but also the presence of the correct cache tags.
    $this->drupalGet('<front>');
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');
    $cid_parts = [Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), ''];
    $cid = implode(':', $cid_parts);
    $cache_entry = \Drupal::cache('page')->get($cid);
@@ -458,14 +458,14 @@ public function testBlockCacheTags() {

    // Now we should have a cache hit again.
    $this->drupalGet('<front>');
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');

    // Delete the "Powered by Drupal" blocks; verify a cache miss.
    $block_storage = \Drupal::entityTypeManager()->getStorage('block');
    $block_storage->load('powered')->delete();
    $block_storage->load('powered-2')->delete();
    $this->drupalGet('<front>');
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
  }

  /**
+1 −3
Original line number Diff line number Diff line
@@ -58,9 +58,7 @@ public function testExport() {
    // Test if header contains file name with hostname and timestamp.
    $request = \Drupal::request();
    $hostname = str_replace('.', '-', $request->getHttpHost());
    $header_content_disposition = $this->drupalGetHeader('content-disposition');
    $header_match = (boolean) preg_match('/attachment; filename="config-' . preg_quote($hostname) . '-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}\.tar\.gz"/', $header_content_disposition);
    $this->assertTrue($header_match, "Header with filename matches the expected format.");
    $this->assertSession()->responseHeaderMatches('content-disposition', '/attachment; filename="config-' . preg_quote($hostname) . '-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}\.tar\.gz"/');

    // Extract the archive and verify it's not empty.
    $file_system = \Drupal::service('file_system');
Loading