function ComponentRenderTest::checkSlots

Same name in this branch
  1. 10 core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest::checkSlots()
Same name in other branches
  1. 11.x core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php \Drupal\Tests\sdc\Kernel\ComponentRenderTest::checkSlots()
  2. 11.x core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest::checkSlots()

Ensure that the slots allow a render array or a scalar when using the render element.

1 call to ComponentRenderTest::checkSlots()
ComponentRenderTest::testRender in core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php
Test that components render correctly.

File

core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php, line 291

Class

ComponentRenderTest
Tests the correct rendering of components.

Namespace

Drupal\Tests\sdc\Kernel

Code

public function checkSlots() : void {
    $slots = [
        'This is the contents of the banner body.',
        [
            '#plain_text' => 'This is the contents of the banner body.',
        ],
    ];
    foreach ($slots as $slot) {
        $build = [
            '#type' => 'component',
            '#component' => 'sdc_test:my-banner',
            '#props' => [
                'heading' => $this->t('I am a banner'),
                'ctaText' => $this->t('Click me'),
                'ctaHref' => 'https://www.example.org',
                'ctaTarget' => '',
            ],
            '#slots' => [
                'banner_body' => $slot,
            ],
        ];
        $crawler = $this->renderComponentRenderArray($build);
        $this->assertNotEmpty($crawler->filter('#sdc-wrapper [data-component-id="sdc_test:my-banner"] .component--my-banner--body:contains("This is the contents of the banner body.")'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.