function TwigLoaderTest::testTwigLoaderAddition

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

Tests adding an additional twig loader to the loader chain.

File

core/modules/system/tests/src/Kernel/Theme/TwigLoaderTest.php, line 24

Class

TwigLoaderTest
Tests adding Twig loaders.

Namespace

Drupal\Tests\system\Kernel\Theme

Code

public function testTwigLoaderAddition() : void {
    $environment = \Drupal::service('twig');
    $template = $environment->load('kittens');
    $this->assertEquals('kittens', $template->render([]), 'Passing "kittens" to the custom Twig loader returns "kittens".');
    $template = $environment->load('meow');
    $this->assertEquals('cats', $template->render([]), 'Passing something other than "kittens" to the custom Twig loader returns "cats".');
}

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