function ComponentKernelTestBase::renderComponentRenderArray
Same name in this branch
- 11.x core/tests/Drupal/Tests/Core/Theme/Component/ComponentKernelTestBase.php \Drupal\Tests\Core\Theme\Component\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.
File
-
core/
tests/ Drupal/ KernelTests/ Components/ ComponentKernelTestBase.php, line 87
Class
- ComponentKernelTestBase
- Defines a base class for component kernel tests.
Namespace
Drupal\KernelTests\ComponentsCode
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.