Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / system / tests / src / Functional / Common / RenderWebTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Common;
4
5 use Drupal\Component\Serialization\Json;
6 use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
7 use Drupal\Tests\BrowserTestBase;
8 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
9
10 /**
11  * Performs integration tests on drupal_render().
12  *
13  * @group Common
14  */
15 class RenderWebTest extends BrowserTestBase {
16
17   use AssertPageCacheContextsAndTagsTrait;
18
19   /**
20    * Modules to enable.
21    *
22    * @var array
23    */
24   public static $modules = ['common_test'];
25
26   /**
27    * Asserts the cache context for the wrapper format is always present.
28    */
29   public function testWrapperFormatCacheContext() {
30     $this->drupalGet('common-test/type-link-active-class');
31     $this->assertIdentical(0, strpos($this->getSession()->getPage()->getContent(), "<!DOCTYPE html>\n<html"));
32     $this->assertIdentical('text/html; charset=UTF-8', $this->drupalGetHeader('Content-Type'));
33     $this->assertTitle('Test active link class | Drupal');
34     $this->assertCacheContext('url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT);
35
36     $this->drupalGet('common-test/type-link-active-class', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'json']]);
37     $this->assertIdentical('application/json', $this->drupalGetHeader('Content-Type'));
38     $json = Json::decode($this->getSession()->getPage()->getContent());
39     $this->assertEqual(['content', 'title'], array_keys($json));
40     $this->assertIdentical('Test active link class', $json['title']);
41     $this->assertCacheContext('url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT);
42   }
43
44 }