function ComponentRenderTest::checkRenderElementAlters
Same name in this branch
- 10 core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest::checkRenderElementAlters()
Same name in other branches
- 11.x core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php \Drupal\Tests\sdc\Kernel\ComponentRenderTest::checkRenderElementAlters()
- 11.x core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest::checkRenderElementAlters()
Ensures the alter callbacks work properly.
1 call to ComponentRenderTest::checkRenderElementAlters()
- 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 259
Class
- ComponentRenderTest
- Tests the correct rendering of components.
Namespace
Drupal\Tests\sdc\KernelCode
public function checkRenderElementAlters() : 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' => '',
],
'#propsAlter' => [
fn($props) => [
$props,
'heading' => $this->t('I am another banner'),
],
],
'#slots' => [
'banner_body' => [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this->t('This is the contents of the banner body.'),
],
],
'#slotsAlter' => [
static fn($slots) => [
$slots,
'banner_body' => [
'#markup' => '<h2>Just something else.</h2>',
],
],
],
];
$crawler = $this->renderComponentRenderArray($build);
$this->assertNotEmpty($crawler->filter('#sdc-wrapper [data-component-id="sdc_test:my-banner"] .component--my-banner--header h3:contains("I am another banner")'));
$this->assertNotEmpty($crawler->filter('#sdc-wrapper [data-component-id="sdc_test:my-banner"] .component--my-banner--body:contains("Just something else.")'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.