annotate core/modules/system/src/Tests/Common/EarlyRenderingControllerTest.php @ 12:7a779792577d

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