You are here

function RenderWebTest::testWrapperFormatCacheContext in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Common/RenderWebTest.php \Drupal\system\Tests\Common\RenderWebTest::testWrapperFormatCacheContext()

Asserts the cache context for the wrapper format is always present.

File

core/modules/system/src/Tests/Common/RenderWebTest.php, line 32
Contains \Drupal\system\Tests\Common\RenderWebTest.

Class

RenderWebTest
Performs integration tests on drupal_render().

Namespace

Drupal\system\Tests\Common

Code

function testWrapperFormatCacheContext() {
  $this
    ->drupalGet('common-test/type-link-active-class');
  $this
    ->assertIdentical(0, strpos($this
    ->getRawContent(), "<!DOCTYPE html>\n<html"));
  $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
    ->getRawContent());
  $this
    ->assertEqual([
    'content',
    'title',
  ], array_keys($json));
  $this
    ->assertIdentical('Test active link class', $json['title']);
  $this
    ->assertCacheContext('url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT);
}