class CvaTest

Same name and namespace in other branches
  1. 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

Expanded class hierarchy of CvaTest

File

core/tests/Drupal/KernelTests/Core/Theme/CvaTest.php, line 17

Namespace

Drupal\KernelTests\Core\Theme
View 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.