RenderTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Render/RenderTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Render;
use Drupal\KernelTests\KernelTestBase;
class RenderTest extends KernelTestBase {
protected static $modules = [
'system',
'common_test',
'theme_test',
];
public function testDrupalRenderThemePreprocessAttached() {
\Drupal::state()
->set('theme_preprocess_attached_test', TRUE);
$test_element = [
'#theme' => 'common_test_render_element',
'foo' => [
'#markup' => 'Kittens!',
],
];
\Drupal::service('renderer')
->renderRoot($test_element);
$expected_attached = [
'library' => [
'test/generic_preprocess',
'test/specific_preprocess',
],
];
$this
->assertEquals($expected_attached, $test_element['#attached'], 'All expected assets from theme preprocess hooks attached.');
\Drupal::state()
->set('theme_preprocess_attached_test', FALSE);
}
public function testRenderChildren() {
$build = [
'#type' => 'container',
'#theme' => 'theme_test_render_element_children',
'#prefix' => 'kangaroo',
'#suffix' => 'kitten',
];
$this
->render($build);
$this
->removeWhiteSpace();
$this
->assertNoRaw('<div>kangarookitten</div>');
}
public function testProcessAttached() {
$build['#attached']['library'][] = 'core/drupal.states';
$build['#attached']['drupal_process_states'][] = [];
$renderer = $this->container
->get('bare_html_page_renderer');
$this
->expectException(\LogicException::class);
$renderer
->renderBarePage($build, '', 'maintenance_page');
}
}