function ComponentRenderTest::testRenderInvalidSlot
Ensure that the slots throw an error for invalid slots.
File
-
core/
tests/ Drupal/ KernelTests/ Components/ ComponentRenderTest.php, line 302
Class
- ComponentRenderTest
- Tests the correct rendering of components.
Namespace
Drupal\KernelTests\ComponentsCode
public function testRenderInvalidSlot() : void {
$build = [
'#type' => 'component',
'#component' => 'sdc_test:my-banner',
'#props' => [
'heading' => 'I am a banner',
'ctaText' => '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.