KernelTestHttpDynamicCacheRequestTest.php
Same filename and directory in other branches
Namespace
Drupal\KernelTestsFile
-
core/
tests/ Drupal/ KernelTests/ KernelTestHttpDynamicCacheRequestTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\KernelTests;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Tests\HttpKernelUiHelperTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\Tests\Traits\Core\Cache\PageCachePolicyTrait;
use PHPUnit\Framework\Attributes\CoversTrait;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Symfony\Component\HttpFoundation\Response;
/**
* Tests making HTTP requests with dynamic page cache in a kernel test.
*/
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]);
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| KernelTestHttpDynamicCacheRequestTest | Tests making HTTP requests with dynamic page cache in a kernel test. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.