Mercurial > hg > isophonics-drupal-site
comparison core/modules/system/src/Tests/Common/EarlyRenderingControllerTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\system\Tests\Common; | |
4 | |
5 use Drupal\Core\Url; | |
6 use Drupal\simpletest\WebTestBase; | |
7 | |
8 /** | |
9 * Verifies that bubbleable metadata of early rendering is not lost. | |
10 * | |
11 * @group Common | |
12 */ | |
13 class EarlyRenderingControllerTest extends WebTestBase { | |
14 | |
15 /** | |
16 * {@inheritdoc} | |
17 */ | |
18 protected $dumpHeaders = TRUE; | |
19 | |
20 /** | |
21 * {@inheritdoc} | |
22 */ | |
23 public static $modules = ['system', 'early_rendering_controller_test']; | |
24 | |
25 /** | |
26 * Tests theme preprocess functions being able to attach assets. | |
27 */ | |
28 public function testEarlyRendering() { | |
29 // Render array: non-early & early. | |
30 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array')); | |
31 $this->assertResponse(200); | |
32 $this->assertRaw('Hello world!'); | |
33 $this->assertCacheTag('foo'); | |
34 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array.early')); | |
35 $this->assertResponse(200); | |
36 $this->assertRaw('Hello world!'); | |
37 $this->assertCacheTag('foo'); | |
38 | |
39 // AjaxResponse: non-early & early. | |
40 // @todo Add cache tags assertion when AjaxResponse is made cacheable in | |
41 // https://www.drupal.org/node/956186. | |
42 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response')); | |
43 $this->assertResponse(200); | |
44 $this->assertRaw('Hello world!'); | |
45 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response.early')); | |
46 $this->assertResponse(200); | |
47 $this->assertRaw('Hello world!'); | |
48 | |
49 // Basic Response object: non-early & early. | |
50 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response')); | |
51 $this->assertResponse(200); | |
52 $this->assertRaw('Hello world!'); | |
53 $this->assertNoCacheTag('foo'); | |
54 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response.early')); | |
55 $this->assertResponse(200); | |
56 $this->assertRaw('Hello world!'); | |
57 $this->assertNoCacheTag('foo'); | |
58 | |
59 // Response object with attachments: non-early & early. | |
60 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments')); | |
61 $this->assertResponse(200); | |
62 $this->assertRaw('Hello world!'); | |
63 $this->assertNoCacheTag('foo'); | |
64 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments.early')); | |
65 $this->assertResponse(500); | |
66 $this->assertRaw('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\early_rendering_controller_test\AttachmentsTestResponse.'); | |
67 | |
68 // Cacheable Response object: non-early & early. | |
69 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-response')); | |
70 $this->assertResponse(200); | |
71 $this->assertRaw('Hello world!'); | |
72 $this->assertNoCacheTag('foo'); | |
73 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-response.early')); | |
74 $this->assertResponse(500); | |
75 $this->assertRaw('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\early_rendering_controller_test\CacheableTestResponse.'); | |
76 | |
77 // Basic domain object: non-early & early. | |
78 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object')); | |
79 $this->assertResponse(200); | |
80 $this->assertRaw('TestDomainObject'); | |
81 $this->assertNoCacheTag('foo'); | |
82 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object.early')); | |
83 $this->assertResponse(200); | |
84 $this->assertRaw('TestDomainObject'); | |
85 $this->assertNoCacheTag('foo'); | |
86 | |
87 // Basic domain object with attachments: non-early & early. | |
88 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object-with-attachments')); | |
89 $this->assertResponse(200); | |
90 $this->assertRaw('AttachmentsTestDomainObject'); | |
91 $this->assertNoCacheTag('foo'); | |
92 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object-with-attachments.early')); | |
93 $this->assertResponse(500); | |
94 $this->assertRaw('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\early_rendering_controller_test\AttachmentsTestDomainObject.'); | |
95 | |
96 // Cacheable Response object: non-early & early. | |
97 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-domain-object')); | |
98 $this->assertResponse(200); | |
99 $this->assertRaw('CacheableTestDomainObject'); | |
100 $this->assertNoCacheTag('foo'); | |
101 $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-domain-object.early')); | |
102 $this->assertResponse(500); | |
103 $this->assertRaw('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\early_rendering_controller_test\CacheableTestDomainObject.'); | |
104 | |
105 // The exceptions are expected. Do not interpret them as a test failure. | |
106 // Not using File API; a potential error must trigger a PHP warning. | |
107 unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); | |
108 } | |
109 | |
110 } |