class CvaTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Theme/CvaTest.php \Drupal\KernelTests\Core\Theme\CvaTest
Tests using CVA in Twig templates.
Attributes
#[Group('Theme')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Theme\CvaTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of CvaTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ CvaTest.php, line 17
Namespace
Drupal\KernelTests\Core\ThemeView source
final class CvaTest extends KernelTestBase {
/**
* Tests rendering a component that uses CVA.
*
* @param string $prop_value
* The value of the prop to pass to the component.
* @param string $expected_class
* The expected CSS class that should appear based on the prop value.
*/
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.