AnnouncementsCacheTest.php
Same filename in other branches
Namespace
Drupal\Tests\announcements_feed\FunctionalFile
-
core/
modules/ announcements_feed/ tests/ src/ Functional/ AnnouncementsCacheTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\announcements_feed\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber;
/**
* Defines a class for testing pages are still cacheable with dynamic page cache.
*
* @group announcements_feed
*/
final class AnnouncementsCacheTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'announcements_feed',
'dynamic_page_cache',
'toolbar',
];
/**
* Tests dynamic page cache.
*/
public function testDynamicPageCache() : void {
$this->drupalLogin($this->drupalCreateUser([
'access toolbar',
'access announcements',
]));
// Front-page is visited right after login.
$this->assertSession()
->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS');
// Reload the page, it should be cached now.
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertSession()
->elementExists('css', '[data-drupal-announce-trigger]');
$this->assertSession()
->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
AnnouncementsCacheTest | Defines a class for testing pages are still cacheable with dynamic page cache. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.