EarlyRenderingControllerTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/Common/EarlyRenderingControllerTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Common;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class EarlyRenderingControllerTest extends BrowserTestBase {
protected static $modules = [
'system',
'early_rendering_controller_test',
];
protected $defaultTheme = 'stark';
public function testEarlyRendering() {
$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');
$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!');
$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');
$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.');
$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.');
$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');
$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.');
$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.');
unlink($this->root . '/' . $this->siteDirectory . '/error.log');
}
}