class RendererRecursionTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php \Drupal\Tests\Core\Render\RendererRecursionTest
- 8.9.x core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php \Drupal\Tests\Core\Render\RendererRecursionTest
- 11.x core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php \Drupal\Tests\Core\Render\RendererRecursionTest
@coversDefaultClass \Drupal\Core\Render\Renderer @group Render
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Render\RendererTestBase extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\Core\Render\RendererRecursionTest extends \Drupal\Tests\Core\Render\RendererTestBase
- class \Drupal\Tests\Core\Render\RendererTestBase extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of RendererRecursionTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ RendererRecursionTest.php, line 11
Namespace
Drupal\Tests\Core\RenderView source
class RendererRecursionTest extends RendererTestBase {
protected function setUpRenderRecursionComplexElements() {
$complex_child_markup = '<p>Imagine this is a render array for an entity.</p>';
$parent_markup = '<p>Rendered!</p>';
$complex_child_template = [
'#cache' => [
'tags' => [
'test:complex_child',
],
],
'#lazy_builder' => [
'Drupal\\Tests\\Core\\Render\\PlaceholdersTest::callback',
[
$this->getRandomGenerator()
->string(),
],
],
'#create_placeholder' => TRUE,
];
return [
$complex_child_markup,
$parent_markup,
$complex_child_template,
];
}
/**
* ::renderRoot() may not be called inside of another ::renderRoot() call.
*
* @covers ::renderRoot
* @covers ::render
* @covers ::doRender
*/
public function testRenderRecursionWithNestedRenderRoot() : void {
[
$complex_child_markup,
$parent_markup,
$complex_child_template,
] = $this->setUpRenderRecursionComplexElements();
$renderer = $this->renderer;
$this->setUpRequest();
$complex_child = $complex_child_template;
$callable = function () use ($renderer, $complex_child) {
$this->expectException(\LogicException::class);
$renderer->renderRoot($complex_child);
};
$page = [
'content' => [
'#pre_render' => [
$callable,
],
'#suffix' => $parent_markup,
],
];
$renderer->renderRoot($page);
}
/**
* ::render() may be called from anywhere.
*
* Including from inside of another ::renderRoot() call. Bubbling must be
* performed.
*
* @covers ::renderRoot
* @covers ::render
* @covers ::doRender
*/
public function testRenderRecursionWithNestedRender() : void {
[
$complex_child_markup,
$parent_markup,
$complex_child_template,
] = $this->setUpRenderRecursionComplexElements();
$renderer = $this->renderer;
$this->setUpRequest();
$callable = function ($markup) {
$this->assertStringStartsWith('<drupal-render-placeholder', (string) $markup, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
return $markup;
};
$page = [
'content' => [
'complex_child' => $complex_child_template,
'#post_render' => [
$callable,
],
'#suffix' => $parent_markup,
],
];
$output = $renderer->renderRoot($page);
$this->assertEquals('<p>This is a rendered placeholder!</p><p>Rendered!</p>', $output, 'Rendered output as expected, with the placeholder replaced.');
$this->assertContains('test:complex_child', $page['#cache']['tags'], 'Cache tag bubbling performed.');
$this->assertContains('dynamic_animal', array_keys($page['#attached']['drupalSettings']), 'Asset bubbling performed.');
}
/**
* ::renderInIsolation() may be called from anywhere.
*
* Including from inside of another ::renderRoot() call.
*
* @covers ::renderRoot
* @covers ::renderInIsolation
*/
public function testRenderRecursionWithNestedRenderInIsolation() : void {
[
$complex_child_markup,
$parent_markup,
$complex_child_template,
] = $this->setUpRenderRecursionComplexElements();
$renderer = $this->renderer;
$this->setUpRequest();
$complex_child = $complex_child_template;
$callable = function ($elements) use ($renderer, $complex_child) {
$elements['#markup'] = $renderer->renderInIsolation($complex_child);
$this->assertEquals('<p>This is a rendered placeholder!</p>', $elements['#markup'], 'Rendered complex child output as expected, with the placeholder replaced.');
return $elements;
};
$page = [
'content' => [
'#pre_render' => [
$callable,
],
'#suffix' => $parent_markup,
],
];
$output = $renderer->renderRoot($page);
$this->assertEquals('<p>This is a rendered placeholder!</p>' . $parent_markup, $output, 'Rendered output as expected, with the placeholder replaced.');
$this->assertNotContains('test:complex_child', $page['#cache']['tags'], 'Cache tag bubbling not performed.');
$this->assertEmpty($page['#attached'], 'Asset bubbling not performed.');
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
RendererRecursionTest::setUpRenderRecursionComplexElements | protected | function | ||||
RendererRecursionTest::testRenderRecursionWithNestedRender | public | function | ::render() may be called from anywhere. | |||
RendererRecursionTest::testRenderRecursionWithNestedRenderInIsolation | public | function | ::renderInIsolation() may be called from anywhere. | |||
RendererRecursionTest::testRenderRecursionWithNestedRenderRoot | public | function | ::renderRoot() may not be called inside of another ::renderRoot() call. | |||
RendererTestBase::$cacheContextsManager | protected | property | ||||
RendererTestBase::$cacheFactory | protected | property | ||||
RendererTestBase::$callableResolver | protected | property | The mocked controller resolver. | |||
RendererTestBase::$currentUserRole | protected | property | The simulated "current" user role, for use in tests with cache contexts. | |||
RendererTestBase::$datetimeTime | protected | property | System time service. | |||
RendererTestBase::$elementInfo | protected | property | The mocked element info. | |||
RendererTestBase::$memoryCache | protected | property | ||||
RendererTestBase::$placeholderGenerator | protected | property | The tested placeholder generator. | 1 | ||
RendererTestBase::$renderCache | protected | property | The tested render cache. | |||
RendererTestBase::$renderer | protected | property | The tested renderer. | |||
RendererTestBase::$rendererConfig | protected | property | The mocked renderer configuration. | |||
RendererTestBase::$requestStack | protected | property | ||||
RendererTestBase::$themeManager | protected | property | The mocked theme manager. | |||
RendererTestBase::assertRenderCacheItem | protected | function | Asserts a render cache item. | |||
RendererTestBase::randomContextValue | protected static | function | Generates a random context value for the placeholder tests. | |||
RendererTestBase::setUp | protected | function | Overrides UnitTestCase::setUp | 4 | ||
RendererTestBase::setUpMemoryCache | protected | function | Sets up a memory-based render cache back-end. | |||
RendererTestBase::setUpRequest | protected | function | Sets up a request object on the request stack. | |||
RendererTestBase::setUpUnusedCache | protected | function | Sets up a render cache back-end that is asserted to be never used. | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.