function AnnouncementsCacheTest::testDynamicPageCache

Same name in other branches
  1. 10 core/modules/announcements_feed/tests/src/Functional/AnnouncementsCacheTest.php \Drupal\Tests\announcements_feed\Functional\AnnouncementsCacheTest::testDynamicPageCache()

Tests dynamic page cache.

File

core/modules/announcements_feed/tests/src/Functional/AnnouncementsCacheTest.php, line 35

Class

AnnouncementsCacheTest
Defines a class for testing pages are still cacheable with dynamic page cache.

Namespace

Drupal\Tests\announcements_feed\Functional

Code

public function testDynamicPageCache() : void {
    $node_type = $this->drupalCreateContentType();
    $node = $this->drupalCreateNode([
        'type' => $node_type->id(),
    ]);
    $this->drupalLogin($this->drupalCreateUser([
        'access toolbar',
        'access announcements',
    ]));
    $this->drupalGet($node->toUrl());
    $this->assertSession()
        ->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS');
    // Reload the page, it should be cached now.
    $this->drupalGet($node->toUrl());
    $this->assertSession()
        ->elementExists('css', '[data-drupal-announce-trigger]');
    $this->assertSession()
        ->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.