You are here

function TwigSettingsTest::testTwigDebugOverride in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Theme/TwigSettingsTest.php \Drupal\system\Tests\Theme\TwigSettingsTest::testTwigDebugOverride()

Ensures Twig engine debug setting can be overridden.

File

core/modules/system/src/Tests/Theme/TwigSettingsTest.php, line 52
Contains \Drupal\system\Tests\Theme\TwigSettingsTest.

Class

TwigSettingsTest
Tests overriding Twig engine settings via settings.php.

Namespace

Drupal\system\Tests\Theme

Code

function testTwigDebugOverride() {

  // Enable debug and rebuild the service container.
  $parameters = $this->container
    ->getParameter('twig.config');
  $parameters['debug'] = TRUE;
  $this
    ->setContainerParameter('twig.config', $parameters);
  $this
    ->rebuildContainer();

  // Check isDebug() via the Twig service container.
  $this
    ->assertTrue($this->container
    ->get('twig')
    ->isDebug(), 'Twig debug enabled.');
  $this
    ->assertTrue($this->container
    ->get('twig')
    ->isAutoReload(), 'Twig automatic reloading is enabled when debug is enabled.');

  // Override auto reload when debug is enabled.
  $parameters = $this->container
    ->getParameter('twig.config');
  $parameters['auto_reload'] = FALSE;
  $this
    ->setContainerParameter('twig.config', $parameters);
  $this
    ->rebuildContainer();
  $this
    ->assertFalse($this->container
    ->get('twig')
    ->isAutoReload(), 'Twig automatic reloading can be disabled when debug is enabled.');

  // Disable debug and check the service container again.
  $parameters = $this->container
    ->getParameter('twig.config');
  $parameters['debug'] = FALSE;
  $this
    ->setContainerParameter('twig.config', $parameters);
  $this
    ->rebuildContainer();
  $this
    ->assertFalse($this->container
    ->get('twig')
    ->isDebug(), 'Twig debug disabled.');
}