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
......@@ -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');
}
}
......@@ -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');
}
......
......@@ -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');
}
/**
......
......@@ -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');
}
/**
......
......@@ -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');
......
......@@ -56,23 +56,23 @@ public function testDynamicPageCache() {
// Cache.
$url = Url::fromUri('route:dynamic_page_cache_test.response');
$this->drupalGet($url);
$this->assertNull($this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Response object returned: Dynamic Page Cache is ignoring.');
$this->assertSession()->responseHeaderDoesNotExist(DynamicPageCacheSubscriber::HEADER);
// Controllers returning CacheableResponseInterface (cacheable response)
// objects are handled by Dynamic Page Cache.
$url = Url::fromUri('route:dynamic_page_cache_test.cacheable_response');
$this->drupalGet($url);
$this->assertEqual('MISS', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Cacheable response object returned: Dynamic Page Cache is active, Dynamic Page Cache MISS.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS');
$this->drupalGet($url);
$this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Cacheable response object returned: Dynamic Page Cache is active, Dynamic Page Cache HIT.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
// Controllers returning render arrays, rendered as HTML responses, are
// handled by Dynamic Page Cache.
$url = Url::fromUri('route:dynamic_page_cache_test.html');
$this->drupalGet($url);
$this->assertEqual('MISS', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as HTML response: Dynamic Page Cache is active, Dynamic Page Cache MISS.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS');
$this->drupalGet($url);
$this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as HTML response: Dynamic Page Cache is active, Dynamic Page Cache HIT.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
// The above is the simple case, where the render array returned by the
// response contains no cache contexts. So let's now test a route/controller
......@@ -82,10 +82,10 @@ public function testDynamicPageCache() {
$url = Url::fromUri('route:dynamic_page_cache_test.html.with_cache_contexts', ['query' => ['animal' => $animal]]);
$this->drupalGet($url);
$this->assertRaw($animal);
$this->assertEqual('MISS', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as HTML response: Dynamic Page Cache is active, Dynamic Page Cache MISS.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS');
$this->drupalGet($url);
$this->assertRaw($animal);
$this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as HTML response: Dynamic Page Cache is active, Dynamic Page Cache HIT.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
// Finally, let's also verify that the 'dynamic_page_cache_test.html'
// route continued to see cache hits if we specify a query argument,
......@@ -93,39 +93,39 @@ public function testDynamicPageCache() {
// Cache hits.
$url = Url::fromUri('route:dynamic_page_cache_test.html', ['query' => ['animal' => 'piglet']]);
$this->drupalGet($url);
$this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as HTML response: Dynamic Page Cache is active, Dynamic Page Cache HIT.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
}
// Controllers returning render arrays, rendered as anything except a HTML
// response, are ignored by Dynamic Page Cache (but only because those
// wrapper formats' responses do not implement CacheableResponseInterface).
$this->drupalGet('dynamic-page-cache-test/html', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertNull($this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as AJAX response: Dynamic Page Cache is ignoring.');
$this->assertSession()->responseHeaderDoesNotExist(DynamicPageCacheSubscriber::HEADER);
$this->drupalGet('dynamic-page-cache-test/html', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog']]);
$this->assertNull($this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as dialog response: Dynamic Page Cache is ignoring.');
$this->assertSession()->responseHeaderDoesNotExist(DynamicPageCacheSubscriber::HEADER);
$this->drupalGet('dynamic-page-cache-test/html', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal']]);
$this->assertNull($this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as modal response: Dynamic Page Cache is ignoring.');
$this->assertSession()->responseHeaderDoesNotExist(DynamicPageCacheSubscriber::HEADER);
// Admin routes are ignored by Dynamic Page Cache.
$this->drupalGet('dynamic-page-cache-test/html/admin');
$this->assertNull($this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Response returned, rendered as HTML response, admin route: Dynamic Page Cache is ignoring');
$this->assertSession()->responseHeaderDoesNotExist(DynamicPageCacheSubscriber::HEADER);
$this->drupalGet('dynamic-page-cache-test/response/admin');
$this->assertNull($this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Response returned, plain response, admin route: Dynamic Page Cache is ignoring');
$this->assertSession()->responseHeaderDoesNotExist(DynamicPageCacheSubscriber::HEADER);
$this->drupalGet('dynamic-page-cache-test/cacheable-response/admin');
$this->assertNull($this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Response returned, cacheable response, admin route: Dynamic Page Cache is ignoring');
$this->assertSession()->responseHeaderDoesNotExist(DynamicPageCacheSubscriber::HEADER);
// Max-age = 0 responses are ignored by Dynamic Page Cache.
$this->drupalGet('dynamic-page-cache-test/html/uncacheable/max-age');
$this->assertEqual('UNCACHEABLE', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as HTML response, but uncacheable: Dynamic Page Cache is running, but not caching.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'UNCACHEABLE');
// 'user' cache context responses are ignored by Dynamic Page Cache.
$this->drupalGet('dynamic-page-cache-test/html/uncacheable/contexts');
$this->assertEqual('UNCACHEABLE', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Render array returned, rendered as HTML response, but uncacheable: Dynamic Page Cache is running, but not caching.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'UNCACHEABLE');
// 'current-temperature' cache tag responses are ignored by Dynamic Page
// Cache.
$this->drupalGet('dynamic-page-cache-test/html/uncacheable/tags');
$this->assertEqual('MISS', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'By default, Drupal has no auto-placeholdering cache tags.');
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS');
}
}
......@@ -75,8 +75,10 @@ protected function doPrivateFileTransferTest() {
file_test_reset();
file_test_set_return('download', ['x-foo' => 'Bar']);
$this->drupalGet($url);
$this->assertEqual($this->drupalGetHeader('x-foo'), 'Bar', 'Found header set by file_test module on private download.');
$this->assertNull($this->drupalGetHeader('x-drupal-cache'), 'Page cache is disabled on private file download.');
// Verify that header is set by file_test module on private download.
$this->assertSession()->responseHeaderEquals('x-foo', 'Bar');
// Verify that page cache is disabled on private file download.
$this->assertSession()->responseHeaderDoesNotExist('x-drupal-cache');
$this->assertSession()->statusCodeEquals(200);
// Ensure hook_file_download is fired correctly.
$this->assertEquals($file->getFileUri(), \Drupal::state()->get('file_test.results')['download'][0][0]);
......
......@@ -141,16 +141,16 @@ public function _testImageFieldFormatters($scheme) {
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
// @todo Remove in https://www.drupal.org/node/2646744.
$this->assertCacheContext('url.site');
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
// Verify that no image style cache tags are found.
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
$this->assertRaw($default_output, 'Image linked to file formatter displaying correctly on full node view.');
// Verify that the image can be downloaded.
$this->assertEqual(file_get_contents($test_image->uri), $this->drupalGet(file_create_url($image_uri)), 'File was downloaded successfully.');
if ($scheme == 'private') {
// Only verify HTTP headers when using private scheme and the headers are
// sent by Drupal.
$this->assertEqual($this->drupalGetHeader('Content-Type'), 'image/png', 'Content-Type header was sent.');
$this->assertTrue(strstr($this->drupalGetHeader('Cache-Control'), 'private') !== FALSE, 'Cache-Control header was sent.');
$this->assertSession()->responseHeaderEquals('Content-Type', 'image/png');
$this->assertSession()->responseHeaderContains('Cache-Control', 'private');
// Log out and ensure the file cannot be accessed.
$this->drupalLogout();
......@@ -173,8 +173,8 @@ public function _testImageFieldFormatters($scheme) {
];
$this->drupalGet('node/' . $nid);
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
// Verify that no image style cache tags are found.
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
$elements = $this->xpath(
'//a[@href=:path]/img[@src=:url and @alt=:alt and @width=:width and @height=:height]',
[
......@@ -368,8 +368,8 @@ public function testImageFieldDefaultImage() {
// Verify that no image is displayed on the page by checking for the class
// that would be used on the image field.
$this->assertSession()->responseNotMatches('<div class="(.*?)field--name-' . strtr($field_name, '_', '-') . '(.*?)">');
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
// Verify that no image style cache tags are found.
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
// Add a default image to the public image field.
$images = $this->drupalGetTestFiles('image');
......@@ -399,8 +399,8 @@ public function testImageFieldDefaultImage() {
$default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->drupalGet('node/' . $node->id());
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
// Verify that no image style cache tags are found.
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
$this->assertRaw($default_output, 'Default image displayed when no user supplied image is present.');
// Create a node with an image attached and ensure that the default image
......@@ -424,8 +424,8 @@ public function testImageFieldDefaultImage() {
$image_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->drupalGet('node/' . $nid);
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
// Verify that no image style cache tags are found.
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
$this->assertNoRaw($default_output, 'Default image is not displayed when user supplied image is present.');
$this->assertRaw($image_output, 'User supplied image is displayed.');
......@@ -475,8 +475,8 @@ public function testImageFieldDefaultImage() {
$default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->drupalGet('node/' . $node->id());
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
// Verify that no image style cache tags are found.
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
$this->assertRaw($default_output, 'Default private image displayed when no user supplied image is present.');
}
......
......@@ -207,19 +207,19 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
// assertRaw can't be used with string containing non UTF-8 chars.
$this->assertNotEmpty(file_get_contents($generated_uri), 'URL returns expected file.');
$image = $this->container->get('image.factory')->get($generated_uri);
$this->assertEqual($this->drupalGetHeader('Content-Type'), $image->getMimeType(), 'Expected Content-Type was reported.');
$this->assertEqual($this->drupalGetHeader('Content-Length'), $image->getFileSize(), 'Expected Content-Length was reported.');
$this->assertSession()->responseHeaderEquals('Content-Type', $image->getMimeType());
$this->assertSession()->responseHeaderEquals('Content-Length', (string) $image->getFileSize());
// Check that we did not download the original file.
$original_image = $this->container->get('image.factory')
->get($original_uri);
$this->assertNotEqual($this->drupalGetHeader('Content-Length'), $original_image->getFileSize());
$this->assertSession()->responseHeaderNotEquals('Content-Length', (string) $original_image->getFileSize());
if ($scheme == 'private') {
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertSession()->responseHeaderEquals('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
// Check that Cache-Control header contains 'no-cache' to prevent caching.
$this->assertSession()->responseHeaderContains('Cache-Control', 'no-cache');
$this->assertEqual($this->drupalGetHeader('X-Image-Owned-By'), 'image_module_test', 'Expected custom header has been added.');
$this->assertSession()->responseHeaderEquals('X-Image-Owned-By', 'image_module_test');
// Make sure that a second request to the already existing derivative
// works too.
......@@ -227,10 +227,10 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
$this->assertSession()->statusCodeEquals(200);
// Check that the second request also returned the generated image.
$this->assertEqual($this->drupalGetHeader('Content-Length'), $image->getFileSize());
$this->assertSession()->responseHeaderEquals('Content-Length', (string) $image->getFileSize());
// Check that we did not download the original file.
$this->assertNotEqual($this->drupalGetHeader('Content-Length'), $original_image->getFileSize());
$this->assertSession()->responseHeaderNotEquals('Content-Length', (string) $original_image->getFileSize());
// Make sure that access is denied for existing style files if we do not
// have access.
......@@ -262,8 +262,8 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
}
}
else {
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertStringNotContainsString('no-cache', $this->drupalGetHeader('Cache-Control'), 'Cache-Control header contains \'no-cache\' to prevent caching.');
$this->assertSession()->responseHeaderEquals('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
$this->assertSession()->responseHeaderNotContains('Cache-Control', 'no-cache');
if ($clean_url) {
// Add some extra chars to the token.
......
......@@ -84,32 +84,32 @@ public function testAcceptLanguageEmptyDefault() {
$this->drupalGet('/system-test/echo/language test', [], ['Accept-Language' => 'en']);
$this->assertSession()->responseHeaderEquals('Content-Language', 'en');
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
// Check with UK browser.
$this->drupalGet('/system-test/echo/language test', [], ['Accept-Language' => 'en-UK,en']);
$this->assertSession()->responseHeaderEquals('Content-Language', 'en');
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
// Check with french browser.
$this->drupalGet('/system-test/echo/language test', [], ['Accept-Language' => 'fr-FR,fr']);
$this->assertSession()->responseHeaderEquals('Content-Language', 'fr');
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
// Check with browser without language settings - should return fallback language.
$this->drupalGet('/system-test/echo/language test', [], ['Accept-Language' => NULL]);
$this->assertSession()->responseHeaderEquals('Content-Language', 'en');
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
// Check with french browser again.
$this->drupalGet('/system-test/echo/language test', [], ['Accept-Language' => 'fr-FR,fr']);
$this->assertSession()->responseHeaderEquals('Content-Language', 'fr');
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
// Check with UK browser.
$this->drupalGet('/system-test/echo/language test', [], ['Accept-Language' => 'en-UK,en']);
$this->assertSession()->responseHeaderEquals('Content-Language', 'en');
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
// Check if prefixed URLs are still cached.
$this->drupalGet('/en/system-test/echo/language test', [], ['Accept-Language' => 'en']);
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\layout_builder\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
......@@ -128,8 +127,7 @@ public function testEntityReferenceFieldBlockCaching() {
*/
protected function verifyPageCacheContainsTags(Url $url, $hit_or_miss, $tags = FALSE) {
$this->drupalGet($url);
$message = new FormattableMarkup('Page cache @hit_or_miss for %path.', ['@hit_or_miss' => $hit_or_miss, '%path' => $url->toString()]);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), $hit_or_miss, $message);
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', $hit_or_miss);
if ($hit_or_miss === 'HIT' && is_array($tags)) {
$cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
......
......@@ -256,8 +256,8 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
->save();
$this->drupalGet('node/' . $nid);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
// No image style cache tag should be found.
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
$this->assertSession()->responseMatches('/<a(.*?)href="' . preg_quote(file_url_transform_relative(file_create_url($image_uri)), '/') . '"(.*?)>\s*<picture/');
// Verify that the image can be downloaded.
......@@ -265,8 +265,8 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
if ($scheme == 'private') {
// Only verify HTTP headers when using private scheme and the headers are
// sent by Drupal.
$this->assertEqual($this->drupalGetHeader('Content-Type'), 'image/png', 'Content-Type header was sent.');
$this->assertTrue(strstr($this->drupalGetHeader('Cache-Control'), 'private') !== FALSE, 'Cache-Control header was sent.');
$this->assertSession()->responseHeaderEquals('Content-Type', 'image/png');
$this->assertSession()->responseHeaderContains('Cache-Control', 'private');
// Log out and ensure the file cannot be accessed.
$this->drupalLogout();
......@@ -311,14 +311,13 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
$this->assertRaw('media="(min-width: 851px)"');
}
$this->assertRaw('/styles/large/');
$cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
$this->assertContains('config:responsive_image.styles.style_one', $cache_tags);
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:responsive_image.styles.style_one');
if (!$empty_styles) {
$this->assertContains('config:image.style.medium', $cache_tags);
$this->assertContains('config:image.style.thumbnail', $cache_tags);
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:image.style.medium');
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:image.style.thumbnail');
$this->assertRaw('type="image/png"');
}
$this->assertContains('config:image.style.large', $cache_tags);
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:image.style.large');
// Test the fallback image style.
$image = \Drupal::service('image.factory')->get($image_uri);
......@@ -338,8 +337,7 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
$this->drupalLogout();
$this->drupalGet($large_style->buildUrl($image_uri));
$this->assertSession()->statusCodeEquals(403);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
$this->assertSession()->responseHeaderNotMatches('X-Drupal-Cache-Tags', '/ image_style\:/');
}
}
......
......@@ -79,7 +79,7 @@ protected function assertPageCacheContextsAndTags(Url $url, array $expected_cont
// Assert cache miss + expected cache contexts + tags.
$this->drupalGet($absolute_url);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
$this->assertCacheTags($expected_tags);
$this->