function TwigRegistryLoaderTest::testTwigNamespaces

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Theme/TwigRegistryLoaderTest.php \Drupal\Tests\system\Functional\Theme\TwigRegistryLoaderTest::testTwigNamespaces()
  2. 8.9.x core/modules/system/tests/src/Functional/Theme/TwigRegistryLoaderTest.php \Drupal\Tests\system\Functional\Theme\TwigRegistryLoaderTest::testTwigNamespaces()
  3. 11.x core/modules/system/tests/src/Functional/Theme/TwigRegistryLoaderTest.php \Drupal\Tests\system\Functional\Theme\TwigRegistryLoaderTest::testTwigNamespaces()

Tests template extension and includes using the Drupal theme registry.

File

core/modules/system/tests/src/Functional/Theme/TwigRegistryLoaderTest.php, line 60

Class

TwigRegistryLoaderTest
Tests Twig registry loader.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testTwigNamespaces() : void {
    // Test the module-provided extend and insert templates.
    $this->drupalGet('twig-theme-test/registry-loader');
    $this->assertSession()
        ->pageTextContains('This line is from twig_theme_test/templates/twig-registry-loader-test-extend.html.twig');
    $this->assertSession()
        ->pageTextContains('This line is from twig_theme_test/templates/twig-registry-loader-test-include.html.twig');
    // Enable a theme that overrides the extend and insert templates to ensure
    // they are picked up by the registry loader.
    $this->config('system.theme')
        ->set('default', 'test_theme_twig_registry_loader')
        ->save();
    $this->drupalGet('twig-theme-test/registry-loader');
    $this->assertSession()
        ->pageTextContains('This line is from test_theme_twig_registry_loader/templates/twig-registry-loader-test-extend.html.twig');
    $this->assertSession()
        ->pageTextContains('This line is from test_theme_twig_registry_loader/templates/twig-registry-loader-test-include.html.twig');
    // Enable overriding theme that overrides the extend and insert templates
    // from the base theme.
    $this->config('system.theme')
        ->set('default', 'test_theme_twig_registry_loader_theme')
        ->save();
    $this->drupalGet('twig-theme-test/registry-loader');
    $this->assertSession()
        ->pageTextContains('This line is from test_theme_twig_registry_loader_theme/templates/twig-registry-loader-test-extend.html.twig');
    $this->assertSession()
        ->pageTextContains('This line is from test_theme_twig_registry_loader_theme/templates/twig-registry-loader-test-include.html.twig');
    // Enable a subtheme for the theme that doesn't have any overrides to make
    // sure that templates are being loaded from the first parent which has the
    // templates.
    $this->config('system.theme')
        ->set('default', 'test_theme_twig_registry_loader_subtheme')
        ->save();
    $this->drupalGet('twig-theme-test/registry-loader');
    $this->assertSession()
        ->pageTextContains('This line is from test_theme_twig_registry_loader_theme/templates/twig-registry-loader-test-extend.html.twig');
    $this->assertSession()
        ->pageTextContains('This line is from test_theme_twig_registry_loader_theme/templates/twig-registry-loader-test-include.html.twig');
}

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