function ComponentRenderTest::checkEmbedWithNested
Same name in this branch
- 11.x core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php \Drupal\Tests\sdc\Kernel\ComponentRenderTest::checkEmbedWithNested()
Same name in other branches
- 10 core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php \Drupal\Tests\sdc\Kernel\ComponentRenderTest::checkEmbedWithNested()
- 10 core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest::checkEmbedWithNested()
Render a card with slots that include a CTA component.
1 call to ComponentRenderTest::checkEmbedWithNested()
- ComponentRenderTest::testRender in core/
tests/ Drupal/ KernelTests/ Components/ ComponentRenderTest.php - Test that components render correctly.
File
-
core/
tests/ Drupal/ KernelTests/ Components/ ComponentRenderTest.php, line 88
Class
- ComponentRenderTest
- Tests the correct rendering of components.
Namespace
Drupal\KernelTests\ComponentsCode
protected function checkEmbedWithNested() : void {
$content = [
'heading' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => 'Just a link',
],
];
$build = [
'#type' => 'inline_template',
'#context' => [
'content' => $content,
],
'#template' => "{% embed 'sdc_theme_test:my-card' with { header: 'Card header', content: content } only %}{% block card_body %}This is a card with a CTA {{ include('sdc_test:my-cta', { text: content.heading, href: 'https://www.example.org', target: '_blank' }, with_context = false) }}{% endblock %}{% endembed %}",
];
$crawler = $this->renderComponentRenderArray($build);
$this->assertNotEmpty($crawler->filter('#sdc-wrapper [data-component-id="sdc_theme_test:my-card"] h2.component--my-card__header:contains("Card header")'));
$this->assertNotEmpty($crawler->filter('#sdc-wrapper [data-component-id="sdc_theme_test:my-card"] .component--my-card__body:contains("This is a card with a CTA")'));
$this->assertNotEmpty($crawler->filter('#sdc-wrapper [data-component-id="sdc_theme_test:my-card"] .component--my-card__body a[data-component-id="sdc_test:my-cta"]:contains("Just a link")'));
$this->assertNotEmpty($crawler->filter('#sdc-wrapper [data-component-id="sdc_theme_test:my-card"] .component--my-card__body a[data-component-id="sdc_test:my-cta"][href="https://www.example.org"][target="_blank"]'));
// Now render a component and assert it contains the debug comments.
$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' => [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this->t('This is the contents of the banner body.'),
],
],
];
$metadata = new BubbleableMetadata();
$this->renderComponentRenderArray($build, $metadata);
$this->assertEquals([
'core/components.sdc_test--my-cta',
'core/components.sdc_test--my-banner',
], $metadata->getAttachments()['library']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.