function 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.
17 calls to ComponentKernelTestBase::renderComponentRenderArray()
- ComponentNegotiatorTest::testRenderWithReplacements in core/
tests/ Drupal/ KernelTests/ Components/ ComponentNegotiatorTest.php - Tests rendering components with component replacement.
- ComponentNodeVisitorTest::testDebugRendersComponentStartWithVariant in core/
tests/ Drupal/ KernelTests/ Components/ ComponentNodeVisitorTest.php - Test debug output for sdc components with component id and variant.
- ComponentNodeVisitorTest::testOtherVisitorsCanModifyTwigNodes in core/
tests/ Drupal/ KernelTests/ Components/ ComponentNodeVisitorTest.php - Test that other visitors can modify Twig nodes.
- ComponentRenderTest::testCheckElementAttributesAndPropAttributesMerging in core/
tests/ Drupal/ KernelTests/ Components/ ComponentRenderTest.php - Ensures the element and prop attributes are merged properly.
- ComponentRenderTest::testRenderArrayObjectTypeCast in core/
tests/ Drupal/ KernelTests/ Components/ ComponentRenderTest.php - Ensure fuzzy coercing of arrays and objects works properly.
File
-
core/
tests/ Drupal/ KernelTests/ Components/ ComponentKernelTestBase.php, line 84
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.