function ComponentRenderTest::checkInvalidSlot

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

Ensure that the slots throw an error for invalid slots.

1 call to ComponentRenderTest::checkInvalidSlot()
ComponentRenderTest::testRender in core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php
Test that components render correctly.

File

core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php, line 320

Class

ComponentRenderTest
Tests the correct rendering of components.

Namespace

Drupal\KernelTests\Components

Code

public function checkInvalidSlot() : void {
    $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' => new \stdClass(),
        ],
    ];
    $this->expectException(InvalidComponentDataException::class);
    $this->expectExceptionMessage('Unable to render component "sdc_test:my-banner". A render array or a scalar is expected for the slot "banner_body" when using the render element with the "#slots" property');
    $this->renderComponentRenderArray($build);
}

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