function ComponentNodeVisitorTest::testDebugRendersComponentStartWithVariant

Test debug output for sdc components with component id and variant.

File

core/tests/Drupal/KernelTests/Components/ComponentNodeVisitorTest.php, line 45

Class

ComponentNodeVisitorTest
Tests the node visitor.

Namespace

Drupal\KernelTests\Components

Code

public function testDebugRendersComponentStartWithVariant() : void {
  // Enable twig theme debug to ensure that any
  // changes to theme debugging format force checking
  // that the auto paragraph filter continues to be applied
  // correctly.
  $twig = \Drupal::service('twig');
  $twig->enableDebug();
  $build = [
    '#type' => 'component',
    '#component' => 'sdc_theme_test:my-card',
    '#variant' => 'vertical',
    '#props' => [
      'header' => 'My header',
    ],
    '#slots' => [
      'card_body' => 'Foo bar',
    ],
  ];
  $crawler = $this->renderComponentRenderArray($build);
  $content = $crawler->html();
  $matches = [];
  \preg_match_all(self::DEBUG_COMPONENT_ID_PATTERN, $content, $matches);
  $this->assertSame($matches[2][0], 'sdc_theme_test:my-card');
  \preg_match_all(self::DEBUG_VARIANT_ID_PATTERN, $content, $matches);
  $this->assertSame($matches[1][0], 'vertical');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.