AnnouncementsCacheTest.php

Same filename and directory in other branches
  1. 10 core/modules/announcements_feed/tests/src/Functional/AnnouncementsCacheTest.php

Namespace

Drupal\Tests\announcements_feed\Functional

File

core/modules/announcements_feed/tests/src/Functional/AnnouncementsCacheTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\announcements_feed\Functional;

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',
    'node',
    'toolbar',
  ];
  
  /**
   * Tests dynamic page cache.
   */
  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');
  }

}

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.