Chris@0: drupalGet(Url::fromRoute('early_rendering_controller_test.render_array')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('Hello world!'); Chris@0: $this->assertCacheTag('foo'); Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array.early')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('Hello world!'); Chris@0: $this->assertCacheTag('foo'); Chris@0: Chris@0: // AjaxResponse: non-early & early. Chris@0: // @todo Add cache tags assertion when AjaxResponse is made cacheable in Chris@0: // https://www.drupal.org/node/956186. Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('Hello world!'); Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response.early')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('Hello world!'); Chris@0: Chris@0: // Basic Response object: non-early & early. Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('Hello world!'); Chris@0: $this->assertNoCacheTag('foo'); Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response.early')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('Hello world!'); Chris@0: $this->assertNoCacheTag('foo'); Chris@0: Chris@0: // Response object with attachments: non-early & early. Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('Hello world!'); Chris@0: $this->assertNoCacheTag('foo'); Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments.early')); Chris@0: $this->assertResponse(500); Chris@0: $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: Chris@0: // Cacheable Response object: non-early & early. Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-response')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('Hello world!'); Chris@0: $this->assertNoCacheTag('foo'); Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-response.early')); Chris@0: $this->assertResponse(500); Chris@0: $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: Chris@0: // Basic domain object: non-early & early. Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('TestDomainObject'); Chris@0: $this->assertNoCacheTag('foo'); Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object.early')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('TestDomainObject'); Chris@0: $this->assertNoCacheTag('foo'); Chris@0: Chris@0: // Basic domain object with attachments: non-early & early. Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object-with-attachments')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('AttachmentsTestDomainObject'); Chris@0: $this->assertNoCacheTag('foo'); Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object-with-attachments.early')); Chris@0: $this->assertResponse(500); Chris@0: $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: Chris@0: // Cacheable Response object: non-early & early. Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-domain-object')); Chris@0: $this->assertResponse(200); Chris@0: $this->assertRaw('CacheableTestDomainObject'); Chris@0: $this->assertNoCacheTag('foo'); Chris@0: $this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-domain-object.early')); Chris@0: $this->assertResponse(500); Chris@0: $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: Chris@0: // The exceptions are expected. Do not interpret them as a test failure. Chris@0: // Not using File API; a potential error must trigger a PHP warning. Chris@0: unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); Chris@0: } Chris@0: Chris@0: }