class KernelTestHttpDynamicCacheRequestTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/KernelTestHttpDynamicCacheRequestTest.php \Drupal\KernelTests\KernelTestHttpDynamicCacheRequestTest

Tests making HTTP requests with dynamic page cache in a kernel test.

Attributes

#[CoversTrait(HttpKernelUiHelperTrait::class)] #[Group('PHPUnit')] #[Group('Test')] #[Group('KernelTests')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of KernelTestHttpDynamicCacheRequestTest

File

core/tests/Drupal/KernelTests/KernelTestHttpDynamicCacheRequestTest.php, line 19

Namespace

Drupal\KernelTests
View source
class KernelTestHttpDynamicCacheRequestTest extends KernelTestBase implements ServiceModifierInterface {
  use PageCachePolicyTrait;
  use UserCreationTrait;
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
    'user',
    'system_test',
    'dynamic_page_cache',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
  }
  
  /**
   * Tests a request is cached and retrieved.
   */
  public function testRequestAuthenticated() : void {
    $this->setUpCurrentUser();
    $this->drupalGet('/system-test/main-content-handling');
    $this->assertEquals(Response::HTTP_OK, $this->getSession()
      ->getStatusCode());
    $this->assertSession()
      ->pageTextContains('Content to test main content fallback');
    $this->assertEquals('MISS', $this->getSession()
      ->getResponseHeaders()['x-drupal-dynamic-cache'][0]);
    $this->drupalGet('/system-test/main-content-handling');
    $this->assertEquals(Response::HTTP_OK, $this->getSession()
      ->getStatusCode());
    $this->assertSession()
      ->pageTextContains('Content to test main content fallback');
    $this->assertEquals('HIT', $this->getSession()
      ->getResponseHeaders()['x-drupal-dynamic-cache'][0]);
  }

}

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