function DevelopmentSettingsFormTest::testTwigDevelopmentMode

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/FunctionalJavascript/Form/DevelopmentSettingsFormTest.php \Drupal\Tests\system\FunctionalJavascript\Form\DevelopmentSettingsFormTest::testTwigDevelopmentMode()

Tests turning on Twig development mode.

@dataProvider twigDevelopmentData

File

core/modules/system/tests/src/FunctionalJavascript/Form/DevelopmentSettingsFormTest.php, line 46

Class

DevelopmentSettingsFormTest
Tests development settings form items for expected behavior.

Namespace

Drupal\Tests\system\FunctionalJavascript\Form

Code

public function testTwigDevelopmentMode(bool $twig_development_mode, ?bool $twig_debug, ?bool $twig_cache_disable) : void {
  $twig_debug = $twig_debug ?? $twig_development_mode;
  $twig_cache_disable = $twig_cache_disable ?? $twig_development_mode;
  $twig_config = \Drupal::getContainer()->getParameter('twig.config');
  self::assertFalse($twig_config['debug']);
  self::assertNull($twig_config['auto_reload']);
  self::assertTrue($twig_config['cache']);
  $this->drupalGet(Url::fromRoute('system.development_settings'));
  if ($twig_development_mode) {
    $this->getSession()
      ->getPage()
      ->checkField('Twig development mode');
    $this->assertSession()
      ->checkboxChecked('Twig debug mode');
    $this->assertSession()
      ->checkboxChecked('Disable Twig cache');
  }
  if (!$twig_debug) {
    $this->getSession()
      ->getPage()
      ->uncheckField('Twig debug mode');
  }
  if (!$twig_cache_disable) {
    $this->getSession()
      ->getPage()
      ->uncheckField('Disable Twig cache');
  }
  $this->getSession()
    ->getPage()
    ->pressButton('Save settings');
  $this->drupalGet(Url::fromRoute('system.status'));
  if (!$twig_development_mode) {
    $this->assertSession()
      ->pageTextNotContains('Twig development mode');
  }
  else {
    $this->assertSession()
      ->pageTextContains('Twig development mode');
    $this->assertSession()
      ->linkExists('development settings page');
  }
  $refreshed_container = $this->initKernel(Request::create('/'));
  $twig_config = $refreshed_container->getParameter('twig.config');
  self::assertEquals($twig_debug, $twig_config['debug']);
  self::assertNull($twig_config['auto_reload']);
  self::assertEquals(!$twig_cache_disable, $twig_config['cache']);
}

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