function ComponentKernelTestBase::renderComponentRenderArray

Same name in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Theme/Component/ComponentKernelTestBase.php \Drupal\Tests\Core\Theme\Component\ComponentKernelTestBase::renderComponentRenderArray()
  2. 11.x core/tests/Drupal/KernelTests/Components/ComponentKernelTestBase.php \Drupal\KernelTests\Components\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.

14 calls to ComponentKernelTestBase::renderComponentRenderArray()
ComponentNegotiatorTest::testRenderWithReplacements in core/tests/Drupal/Tests/Core/Theme/Component/ComponentNegotiatorTest.php
Tests rendering components with component replacement.
ComponentNodeVisitorTest::testOtherVisitorsCanModifyTwigNodes in core/tests/Drupal/KernelTests/Components/ComponentNodeVisitorTest.php
Test that other visitors can modify Twig nodes.
ComponentRenderTest::checkArrayObjectTypeCast in core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php
Ensure fuzzy coercing of arrays and objects works properly.
ComponentRenderTest::checkAttributeMerging in core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php
Ensures the attributes are merged properly.
ComponentRenderTest::checkEmbedWithNested in core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php
Render a card with slots that include a CTA component.

... See full list

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\Component

Code

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.