TwigRegistryLoaderTest.php in Drupal 8
File
core/modules/system/tests/src/Functional/Theme/TwigRegistryLoaderTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Theme;
use Drupal\Tests\BrowserTestBase;
use Twig\TemplateWrapper;
class TwigRegistryLoaderTest extends BrowserTestBase {
public static $modules = [
'twig_theme_test',
'block',
];
protected $defaultTheme = 'stark';
protected $twig;
protected function setUp() {
parent::setUp();
\Drupal::service('theme_installer')
->install([
'test_theme_twig_registry_loader',
'test_theme_twig_registry_loader_theme',
'test_theme_twig_registry_loader_subtheme',
]);
$this->twig = \Drupal::service('twig');
}
public function assertTwigTemplate($value, $message = '') {
$this
->assertInstanceOf(TemplateWrapper::class, $value, $message);
}
public function testTemplateDiscovery() {
$this
->assertTwigTemplate($this->twig
->load('block.html.twig'), 'Found block.html.twig in block module.');
}
public function testTwigNamespaces() {
$this
->drupalGet('twig-theme-test/registry-loader');
$this
->assertText('This line is from twig_theme_test/templates/twig-registry-loader-test-extend.html.twig');
$this
->assertText('This line is from twig_theme_test/templates/twig-registry-loader-test-include.html.twig');
$this
->config('system.theme')
->set('default', 'test_theme_twig_registry_loader')
->save();
$this
->drupalGet('twig-theme-test/registry-loader');
$this
->assertText('This line is from test_theme_twig_registry_loader/templates/twig-registry-loader-test-extend.html.twig');
$this
->assertText('This line is from test_theme_twig_registry_loader/templates/twig-registry-loader-test-include.html.twig');
$this
->config('system.theme')
->set('default', 'test_theme_twig_registry_loader_theme')
->save();
$this
->drupalGet('twig-theme-test/registry-loader');
$this
->assertText('This line is from test_theme_twig_registry_loader_theme/templates/twig-registry-loader-test-extend.html.twig');
$this
->assertText('This line is from test_theme_twig_registry_loader_theme/templates/twig-registry-loader-test-include.html.twig');
$this
->config('system.theme')
->set('default', 'test_theme_twig_registry_loader_subtheme')
->save();
$this
->drupalGet('twig-theme-test/registry-loader');
$this
->assertText('This line is from test_theme_twig_registry_loader_theme/templates/twig-registry-loader-test-extend.html.twig');
$this
->assertText('This line is from test_theme_twig_registry_loader_theme/templates/twig-registry-loader-test-include.html.twig');
}
}