class EarlyRenderingControllerTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Common/EarlyRenderingControllerTest.php \Drupal\Tests\system\Functional\Common\EarlyRenderingControllerTest
- 10 core/modules/system/tests/src/Functional/Common/EarlyRenderingControllerTest.php \Drupal\Tests\system\Functional\Common\EarlyRenderingControllerTest
- 8.9.x core/modules/system/tests/src/Functional/Common/EarlyRenderingControllerTest.php \Drupal\Tests\system\Functional\Common\EarlyRenderingControllerTest
Verifies that bubbleable metadata of early rendering is not lost.
@group Common
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Common\EarlyRenderingControllerTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of EarlyRenderingControllerTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Common/ EarlyRenderingControllerTest.php, line 13
Namespace
Drupal\Tests\system\Functional\CommonView source
class EarlyRenderingControllerTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'early_rendering_controller_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests theme preprocess functions being able to attach assets.
*/
public function testEarlyRendering() {
// Render array: non-early & early.
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Hello world!');
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'foo');
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array.early'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Hello world!');
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'foo');
// AjaxResponse: non-early & early.
// @todo Add cache tags assertion when AjaxResponse is made cacheable in
// https://www.drupal.org/node/956186.
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Hello world!');
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response.early'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Hello world!');
// Basic Response object: non-early & early.
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.response'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Hello world!');
$this->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.response.early'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Hello world!');
$this->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
// Response object with attachments: non-early & early.
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Hello world!');
$this->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments.early'));
$this->assertSession()
->statusCodeEquals(500);
$this->assertSession()
->pageTextContains('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.');
// Cacheable Response object: non-early & early.
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-response'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Hello world!');
$this->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-response.early'));
$this->assertSession()
->statusCodeEquals(500);
$this->assertSession()
->pageTextContains('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.');
// Basic domain object: non-early & early.
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('TestDomainObject');
$this->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object.early'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('TestDomainObject');
$this->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
// Basic domain object with attachments: non-early & early.
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object-with-attachments'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('AttachmentsTestDomainObject');
$this->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.domain-object-with-attachments.early'));
$this->assertSession()
->statusCodeEquals(500);
$this->assertSession()
->pageTextContains('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.');
// Cacheable Response object: non-early & early.
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-domain-object'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('CacheableTestDomainObject');
$this->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.cacheable-domain-object.early'));
$this->assertSession()
->statusCodeEquals(500);
$this->assertSession()
->pageTextContains('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.');
// The exceptions are expected. Do not interpret them as a test failure.
// Not using File API; a potential error must trigger a PHP warning.
unlink($this->root . '/' . $this->siteDirectory . '/error.log');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.