class ComponentNodeVisitorTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Components/ComponentNodeVisitorTest.php \Drupal\KernelTests\Components\ComponentNodeVisitorTest
- 10 core/tests/Drupal/KernelTests/Components/ComponentNodeVisitorTest.php \Drupal\KernelTests\Components\ComponentNodeVisitorTest
Tests the node visitor.
Attributes
#[CoversClass(ComponentNodeVisitor::class)]
#[Group('sdc')]
#[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, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Components\ComponentKernelTestBase extends \Drupal\KernelTests\KernelTestBase
- class \Drupal\KernelTests\Components\ComponentNodeVisitorTest extends \Drupal\KernelTests\Components\ComponentKernelTestBase
- class \Drupal\KernelTests\Components\ComponentKernelTestBase extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of ComponentNodeVisitorTest
File
-
core/
tests/ Drupal/ KernelTests/ Components/ ComponentNodeVisitorTest.php, line 15
Namespace
Drupal\KernelTests\ComponentsView source
class ComponentNodeVisitorTest extends ComponentKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'sdc_other_node_visitor',
];
/**
* {@inheritdoc}
*/
protected static $themes = [
'sdc_theme_test',
];
const DEBUG_COMPONENT_ID_PATTERN = '/<!-- ([\\n\\s\\S]*) Component start: ([\\SA-Za-z+-:]+) -->/';
const DEBUG_VARIANT_ID_PATTERN = '/<!-- [\\n\\s\\S]* with variant: "([\\SA-Za-z+-]+)" -->/';
/**
* Test that other visitors can modify Twig nodes.
*/
public function testOtherVisitorsCanModifyTwigNodes() : void {
$build = [
'#type' => 'inline_template',
'#template' => "{% embed('sdc_theme_test_base:my-card-no-schema') %}{% block card_body %}Foo bar{% endblock %}{% endembed %}",
];
$this->renderComponentRenderArray($build);
// If this is reached, the test passed.
$this->assertTrue(TRUE);
}
/**
* Test debug output for sdc components with component id and variant.
*/
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.