TwigSettingsTest.php in Zircon Profile 8.0
File
core/modules/system/src/Tests/Theme/TwigSettingsTest.php
View source
<?php
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\PhpStorage\PhpStorageFactory;
class TwigSettingsTest extends WebTestBase {
public static $modules = array(
'theme_test',
);
function testTwigAutoReloadOverride() {
$parameters = $this->container
->getParameter('twig.config');
$parameters['auto_reload'] = TRUE;
$this
->setContainerParameter('twig.config', $parameters);
$this
->rebuildContainer();
$this
->assertTrue($this->container
->get('twig')
->isAutoReload(), 'Automatic reloading of Twig templates 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(), 'Automatic reloading of Twig templates disabled.');
}
function testTwigDebugOverride() {
$parameters = $this->container
->getParameter('twig.config');
$parameters['debug'] = TRUE;
$this
->setContainerParameter('twig.config', $parameters);
$this
->rebuildContainer();
$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.');
$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.');
$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.');
}
function testTwigCacheOverride() {
$extension = twig_extension();
$theme_handler = $this->container
->get('theme_handler');
$theme_handler
->install(array(
'test_theme',
));
$theme_handler
->setDefault('test_theme');
\Drupal::theme()
->setActiveTheme(\Drupal::service('theme.initialization')
->getActiveThemeByName('test_theme'));
$this->container
->set('theme.registry', NULL);
$registry = $this->container
->get('theme.registry');
$registry
->reset();
$templates = $registry
->getRuntime();
$info = $templates
->get('theme_test_template_test');
$template_filename = $info['path'] . '/' . $info['template'] . $extension;
$cache_filename = $this->container
->get('twig')
->getCacheFilename($template_filename);
$this
->drupalGet('theme-test/template-test');
$this
->assertTrue(PhpStorageFactory::get('twig')
->exists($cache_filename), 'Cached Twig template found.');
$parameters = $this->container
->getParameter('twig.config');
$parameters['cache'] = FALSE;
$this
->setContainerParameter('twig.config', $parameters);
$this
->rebuildContainer();
$this
->assertFalse($this->container
->get('twig')
->getCache(), 'Twig environment has caching disabled.');
}
public function testTwigInlineWithAutoReload() {
$parameters = $this->container
->getParameter('twig.config');
$parameters['auto_reload'] = TRUE;
$parameters['debug'] = TRUE;
$this
->setContainerParameter('twig.config', $parameters);
$this
->rebuildContainer();
$this
->drupalGet('theme-test/inline-template-test');
$this
->assertResponse(200);
$this
->drupalGet('theme-test/inline-template-test');
$this
->assertResponse(200);
}
}