class DevelopmentSettingsFormTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/FunctionalJavascript/Form/DevelopmentSettingsFormTest.php \Drupal\Tests\system\FunctionalJavascript\Form\DevelopmentSettingsFormTest
Tests development settings form items for expected behavior.
@group Form
Hierarchy
- class \Drupal\Tests\system\FunctionalJavascript\Form\DevelopmentSettingsFormTest
Expanded class hierarchy of DevelopmentSettingsFormTest
File
-
core/
modules/ system/ tests/ src/ FunctionalJavascript/ Form/ DevelopmentSettingsFormTest.php, line 17
Namespace
Drupal\Tests\system\FunctionalJavascript\FormView source
class DevelopmentSettingsFormTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'dynamic_page_cache',
'page_cache',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$admin_user = $this->drupalCreateUser([
'administer site configuration',
]);
$this->drupalLogin($admin_user);
}
/**
* Tests turning on Twig development mode.
*
* @dataProvider twigDevelopmentData
*/
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']);
}
/**
* Test data for Twig development mode.
*
* @return array[]
*/
public static function twigDevelopmentData() : array {
return [
'Twig development mode checked only' => [
TRUE,
NULL,
NULL,
],
'Twig debug mode only, keep Twig cache' => [
TRUE,
TRUE,
FALSE,
],
'Twig debug mode off, disable Twig cache' => [
TRUE,
FALSE,
TRUE,
],
'No changes' => [
FALSE,
NULL,
NULL,
],
];
}
/**
* Tests disabling cache bins which cache markup.
*/
public function testDisabledRenderedOutputCacheBins() : void {
self::assertFalse(\Drupal::getContainer()->has('cache.backend.null'));
$this->drupalGet(Url::fromRoute('system.development_settings'));
$this->getSession()
->getPage()
->checkField('Do not cache markup');
$this->getSession()
->getPage()
->pressButton('Save settings');
$this->drupalGet(Url::fromRoute('system.status'));
$this->assertSession()
->pageTextContains('Markup caching disabled');
$this->assertSession()
->linkExists('development settings page');
$refreshed_container = $this->initKernel(Request::create('/'));
self::assertTrue($refreshed_container->has('cache.backend.null'));
$cache_bins = [
'page',
'dynamic_page_cache',
'render',
];
foreach ($cache_bins as $cache_bin) {
self::assertInstanceOf(NullBackend::class, $refreshed_container->get("cache.{$cache_bin}"));
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
DevelopmentSettingsFormTest::$defaultTheme | protected | property | The theme to install as the default for testing. |
DevelopmentSettingsFormTest::$modules | protected static | property | Modules to install. |
DevelopmentSettingsFormTest::setUp | protected | function | |
DevelopmentSettingsFormTest::testDisabledRenderedOutputCacheBins | public | function | Tests disabling cache bins which cache markup. |
DevelopmentSettingsFormTest::testTwigDevelopmentMode | public | function | Tests turning on Twig development mode. |
DevelopmentSettingsFormTest::twigDevelopmentData | public static | function | Test data for Twig development mode. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.