3 namespace Drupal\Tests\system\Functional\Common;
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;
11 * Performs integration tests on drupal_render().
15 class RenderWebTest extends BrowserTestBase {
17 use AssertPageCacheContextsAndTagsTrait;
24 public static $modules = ['common_test'];
27 * Asserts the cache context for the wrapper format is always present.
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);
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);