PageCacheTagsTestBase.php in Zircon Profile 8
File
core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php
View source
<?php
namespace Drupal\system\Tests\Cache;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
use Drupal\Component\Utility\SafeMarkup;
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 = SafeMarkup::format('Page cache @hit_or_miss for %path.', array(
'@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 = array(
$absolute_url,
'html',
);
$cid = implode(':', $cid_parts);
$cache_entry = \Drupal::cache('render')
->get($cid);
sort($cache_entry->tags);
$tags = array_unique($tags);
sort($tags);
$this
->assertIdentical($cache_entry->tags, $tags);
}
}
}