class RendererRecursionTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Render\RendererTestBase
- class \Drupal\Tests\Core\Render\RendererRecursionTest
- class \Drupal\Tests\Core\Render\RendererTestBase
Expanded class hierarchy of RendererRecursionTest
File
- core/
tests/ Drupal/ Tests/ Core/ Render/ RendererRecursionTest.php, line 16 - Contains \Drupal\Tests\Core\Render\RendererRecursionTest.
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
*
* @expectedException \LogicException
*/
public function testRenderRecursionWithNestedRenderRoot() {
list($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) {
$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() {
list($complex_child_markup, $parent_markup, $complex_child_template) = $this
->setUpRenderRecursionComplexElements();
$renderer = $this->renderer;
$this
->setUpRequest();
$callable = function ($markup) use ($renderer, $complex_child_template) {
$this
->assertTrue(strpos($markup, '<drupal-render-placeholder') === 0, '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
->assertTrue(in_array('test:complex_child', $page['#cache']['tags']), 'Cache tag bubbling performed.');
$this
->assertTrue(in_array('dynamic_animal', array_keys($page['#attached']['drupalSettings'])), 'Asset bubbling performed.');
}
/**
* ::renderPlain() may be called from anywhere.
*
* Including from inside of another ::renderRoot() call.
*
* @covers ::renderRoot
* @covers ::renderPlain
*/
public function testRenderRecursionWithNestedRenderPlain() {
list($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, $parent_markup) {
$elements['#markup'] = $renderer
->renderPlain($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
->assertFalse(in_array('test:complex_child', $page['#cache']['tags']), 'Cache tag bubbling not performed.');
$this
->assertTrue(empty($page['#attached']), 'Asset bubbling not performed.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RendererRecursionTest:: |
protected | function | ||
RendererRecursionTest:: |
public | function | ::render() may be called from anywhere. | |
RendererRecursionTest:: |
public | function | ::renderPlain() may be called from anywhere. | |
RendererRecursionTest:: |
public | function | ::renderRoot() may not be called inside of another ::renderRoot() call. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The mocked controller resolver. | |
RendererTestBase:: |
protected | property | The simulated "current" user role, for use in tests with cache contexts. | |
RendererTestBase:: |
protected | property | The mocked element info. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The tested placeholder generator. | 1 |
RendererTestBase:: |
protected | property | The tested render cache. | |
RendererTestBase:: |
protected | property | The tested renderer. | |
RendererTestBase:: |
protected | property | The mocked renderer configuration. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The mocked theme manager. | |
RendererTestBase:: |
protected | function | Asserts a render cache item. | |
RendererTestBase:: |
protected | function | Generates a random context value for the placeholder tests. | |
RendererTestBase:: |
protected | function |
Overrides UnitTestCase:: |
2 |
RendererTestBase:: |
protected | function | Sets up a memory-based render cache back-end. | |
RendererTestBase:: |
protected | function | Sets up a request object on the request stack. | |
RendererTestBase:: |
protected | function | Sets up a render cache back-end that is asserted to be never used. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |