function ComponentRendererTrait::renderComponentRenderArray

Same name in other branches
  1. 11.x core/modules/sdc/tests/src/Traits/ComponentRendererTrait.php \Drupal\Tests\sdc\Traits\ComponentRendererTrait::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 ComponentRendererTrait::renderComponentRenderArray()
ComponentNegotiatorTest::testRenderWithReplacements in core/modules/sdc/tests/src/Kernel/ComponentNegotiatorTest.php
Tests rendering components with component replacement.
ComponentNodeVisitorTest::testOtherVisitorsCanModifyTwigNodes in core/modules/sdc/tests/src/Kernel/ComponentNodeVisitorTest.php
Test that other visitors can modify Twig nodes.
ComponentRenderTest::checkArrayObjectTypeCast in core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php
Ensure fuzzy coercing of arrays and objects works properly.
ComponentRenderTest::checkAttributeMerging in core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php
Ensures the attributes are merged properly.
ComponentRenderTest::checkEmbedWithNested in core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php
Render a card with slots that include a CTA component.

... See full list

File

core/modules/sdc/tests/src/Traits/ComponentRendererTrait.php, line 29

Class

ComponentRendererTrait
Defines a trait for rendering components.

Namespace

Drupal\Tests\sdc\Traits

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.