You are here

public function TwigEnvironmentTest::testTemplateNotFoundException in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php \Drupal\system\Tests\Theme\TwigEnvironmentTest::testTemplateNotFoundException()

Tests that exceptions are thrown when a template is not found.

File

core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php, line 102
Contains \Drupal\system\Tests\Theme\TwigEnvironmentTest.

Class

TwigEnvironmentTest
Tests the twig environment.

Namespace

Drupal\system\Tests\Theme

Code

public function testTemplateNotFoundException() {

  /** @var \Drupal\Core\Template\TwigEnvironment $environment */
  $environment = \Drupal::service('twig');
  try {
    $environment
      ->loadTemplate('this-template-does-not-exist.html.twig')
      ->render(array());
    $this
      ->fail('Did not throw an exception as expected.');
  } catch (\Twig_Error_Loader $e) {
    $this
      ->assertTrue(strpos($e
      ->getMessage(), 'Template "this-template-does-not-exist.html.twig" is not defined') === 0);
  }
}