You are here

public function TwigSettingsTest::testTwigDebugOverride in Drupal 9

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

Ensures Twig engine debug setting can be overridden.

File

core/modules/system/tests/src/Functional/Theme/TwigSettingsTest.php, line 52

Class

TwigSettingsTest
Tests overriding Twig engine settings via settings.php.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public 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.');
}