function ComponentKernelTestBase::renderComponentRenderArray
Same name in this branch
- 11.x core/tests/Drupal/KernelTests/Components/ComponentKernelTestBase.php \Drupal\KernelTests\Components\ComponentKernelTestBase::renderComponentRenderArray()
Same name in other branches
- 10 core/tests/Drupal/Tests/Core/Theme/Component/ComponentKernelTestBase.php \Drupal\Tests\Core\Theme\Component\ComponentKernelTestBase::renderComponentRenderArray()
Renders a component for testing sake.
Parameters
array $component: Component render array.
\Drupal\Core\Render\BubbleableMetadata|null $metadata: Bubble metadata.
Return value
\Symfony\Component\DomCrawler\Crawler Crawler for introspecting the rendered component.
1 call to ComponentKernelTestBase::renderComponentRenderArray()
- ComponentNegotiatorTest::testRenderWithReplacements in core/
tests/ Drupal/ Tests/ Core/ Theme/ Component/ ComponentNegotiatorTest.php - Tests rendering components with component replacement.
File
-
core/
tests/ Drupal/ Tests/ Core/ Theme/ Component/ ComponentKernelTestBase.php, line 87
Class
- ComponentKernelTestBase
- Defines a base class for component kernel tests.
Namespace
Drupal\Tests\Core\Theme\ComponentCode
protected function renderComponentRenderArray(array $component, ?BubbleableMetadata $metadata = NULL) : Crawler {
$component = [
'#type' => 'container',
'#attributes' => [
'id' => 'sdc-wrapper',
],
'component' => $component,
];
$metadata = $metadata ?: new BubbleableMetadata();
$context = new RenderContext();
$renderer = \Drupal::service('renderer');
$output = $renderer->executeInRenderContext($context, fn() => $renderer->render($component));
if (!$context->isEmpty()) {
$metadata->addCacheableDependency($context->pop());
}
return new Crawler((string) $output);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.