public function RenderWebTest::testWrapperFormatCacheContext in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Common/RenderWebTest.php \Drupal\Tests\system\Functional\Common\RenderWebTest::testWrapperFormatCacheContext()
- 9 core/modules/system/tests/src/Functional/Common/RenderWebTest.php \Drupal\Tests\system\Functional\Common\RenderWebTest::testWrapperFormatCacheContext()
Asserts the cache context for the wrapper format is always present.
File
- core/
modules/ system/ tests/ src/ Functional/ Common/ RenderWebTest.php, line 34
Class
- RenderWebTest
- Performs integration tests on \Drupal::service('renderer')->render().
Namespace
Drupal\Tests\system\Functional\CommonCode
public function testWrapperFormatCacheContext() {
$this
->drupalGet('common-test/type-link-active-class');
$this
->assertStringStartsWith("<!DOCTYPE html>\n<html", $this
->getSession()
->getPage()
->getContent());
$this
->assertSession()
->responseHeaderEquals('Content-Type', 'text/html; charset=UTF-8');
$this
->assertSession()
->titleEquals('Test active link class | Drupal');
$this
->assertCacheContext('url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT);
$this
->drupalGet('common-test/type-link-active-class', [
'query' => [
MainContentViewSubscriber::WRAPPER_FORMAT => 'json',
],
]);
$this
->assertSession()
->responseHeaderEquals('Content-Type', 'application/json');
$json = Json::decode($this
->getSession()
->getPage()
->getContent());
$this
->assertEquals([
'content',
'title',
], array_keys($json));
$this
->assertSame('Test active link class', $json['title']);
$this
->assertCacheContext('url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT);
}