PageCacheTagsTestBase.php in Drupal 8
File
core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php
View source
<?php
namespace Drupal\system\Tests\Cache;
@trigger_error(__NAMESPACE__ . '\\PageCacheTagsTestBase is deprecated for removal before Drupal 9.0.0. Use \\Drupal\\Tests\\system\\Functional\\Cache\\PageCacheTagsTestBase instead. See https://www.drupal.org/node/2999939', E_USER_DEPRECATED);
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
use Drupal\Component\Render\FormattableMarkup;
abstract class PageCacheTagsTestBase extends WebTestBase {
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,
'html',
];
$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);
}
}
}