function RenderWebTest::testWrapperFormatCacheContext

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Common/RenderWebTest.php \Drupal\Tests\system\Functional\Common\RenderWebTest::testWrapperFormatCacheContext()
  2. 10 core/modules/system/tests/src/Functional/Common/RenderWebTest.php \Drupal\Tests\system\Functional\Common\RenderWebTest::testWrapperFormatCacheContext()
  3. 11.x 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 <a href="/api/drupal/core%21includes%21common.inc/function/drupal_render/8.9.x" title="Renders HTML given a structured array tree." class="local">drupal_render</a>().

Namespace

Drupal\Tests\system\Functional\Common

Code

public function testWrapperFormatCacheContext() {
    $this->drupalGet('common-test/type-link-active-class');
    $this->assertStringStartsWith("<!DOCTYPE html>\n<html", $this->getSession()
        ->getPage()
        ->getContent());
    $this->assertIdentical('text/html; charset=UTF-8', $this->drupalGetHeader('Content-Type'));
    $this->assertTitle('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->assertIdentical('application/json', $this->drupalGetHeader('Content-Type'));
    $json = Json::decode($this->getSession()
        ->getPage()
        ->getContent());
    $this->assertEqual([
        'content',
        'title',
    ], array_keys($json));
    $this->assertIdentical('Test active link class', $json['title']);
    $this->assertCacheContext('url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT);
}

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