ComponentsTest.php in Components! 8.2
File
tests/src/Functional/ComponentsTest.php
View source
<?php
namespace Drupal\Tests\components\Functional;
use Drupal\Tests\BrowserTestBase;
class ComponentsTest extends BrowserTestBase {
protected static $modules = [
'system',
'components',
'components_test',
];
protected $defaultTheme = 'components_test_theme';
protected function render(array &$elements) : string {
return $this->container
->get('renderer')
->renderRoot($elements);
}
public function testLoadTemplate() {
$result = NULL;
try {
$element = [
'#theme' => 'components_test',
];
$result = $this
->render($element);
} catch (\Exception $e) {
$this
->fail('No Exception expected; "' . $e
->getMessage() . '" thrown during: ' . $this
->getName());
}
foreach ([
'This is the "@components_test/components-test.twig" template from the components_test module.',
'This is the "@components/components-test-active-theme.twig" template from the components_test_theme theme.',
'This is the "@components/components-test-base-theme.twig" template from the components_test_base_theme theme.',
'This is the "@components/components-test-module.twig" template from the components_test module.',
] as $foundString) {
if (method_exists($this, 'assertStringContainsString')) {
$this
->assertStringContainsString($foundString, $result);
}
else {
$this
->assertContains($foundString, $result);
}
}
foreach ([
'This is the "@components/components-test-active-theme.twig" template from the components_test_base_theme theme.',
'This is the "@components/components-test-active-theme.twig" template from the components_test module.',
'This is the "@components/components-test-base-theme.twig" template from the components_test module.',
] as $notFoundString) {
if (method_exists($this, 'assertStringNotContainsString')) {
$this
->assertStringNotContainsString($notFoundString, $result);
}
else {
$this
->assertContains($notFoundString, $result);
}
}
$foundString = 'This is the "@system/components-test-protected-twig-namespaces-alter.twig" template from the components_test module.';
if (method_exists($this, 'assertStringContainsString')) {
$this
->assertStringContainsString($foundString, $result);
}
else {
$this
->assertContains($foundString, $result);
}
}
}
Classes
Name |
Description |
ComponentsTest |
Tests the components module in a fully loaded Drupal instance. |