function CvaTest::testCva
Same name and namespace in other branches
- main core/tests/Drupal/KernelTests/Core/Theme/CvaTest.php \Drupal\KernelTests\Core\Theme\CvaTest::testCva()
Tests rendering a component that uses CVA.
Attributes
#[TestWith([
'nice',
'friendly',
])]
#[TestWith([
'mean',
'unfriendly',
])]
Parameters
string $prop_value: The value of the prop to pass to the component.
string $expected_class: The expected CSS class that should appear based on the prop value.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ CvaTest.php, line 29
Class
- CvaTest
- Tests using CVA in Twig templates.
Namespace
Drupal\KernelTests\Core\ThemeCode
public function testCva(string $prop_value, string $expected_class) : void {
\Drupal::service(ThemeInstallerInterface::class)->install([
'sdc_theme_test',
]);
$build = [
'#type' => 'component',
'#component' => 'sdc_theme_test:cva',
'#props' => [
'friendliness' => $prop_value,
],
];
$rendered = (string) \Drupal::service(RendererInterface::class)->renderRoot($build);
$expected_html = sprintf(' class="cva-friendliness %s"', $expected_class);
$this->assertStringContainsString($expected_html, $rendered);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.