PageCacheTagsTestBase.php in Drupal 8
File
core/modules/system/tests/src/Functional/Cache/PageCacheTagsTestBase.php
View source
<?php
namespace Drupal\Tests\system\Functional\Cache;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Component\Render\FormattableMarkup;
abstract class PageCacheTagsTestBase extends BrowserTestBase {
protected $dumpHeaders = TRUE;
protected function setUp() {
parent::setUp();
$config = $this
->config('system.performance');
$config
->set('cache.page.max_age', 3600);
$config
->save();
}
protected function verifyPageCache(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);
if ($hit_or_miss === 'HIT' && is_array($tags)) {
$absolute_url = $url
->setAbsolute()
->toString();
$cid_parts = [
$absolute_url,
'',
];
$cid = implode(':', $cid_parts);
$cache_entry = \Drupal::cache('page')
->get($cid);
sort($cache_entry->tags);
$tags = array_unique($tags);
sort($tags);
$this
->assertIdentical($cache_entry->tags, $tags);
}
}
protected function verifyDynamicPageCache(Url $url, $hit_or_miss) {
$this
->drupalGet($url);
$message = new FormattableMarkup('Dynamic page cache @hit_or_miss for %path.', [
'@hit_or_miss' => $hit_or_miss,
'%path' => $url
->toString(),
]);
$this
->assertSame($hit_or_miss, $this
->getSession()
->getResponseHeader('X-Drupal-Dynamic-Cache'), $message);
}
}