diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php index 9f8db4c..c4d4fe7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\Theme; use Drupal\simpletest\WebTestBase; +use Drupal\Component\PhpStorage\PhpStorageFactory; /** * Tests Twig engine configuration via settings.php. @@ -29,13 +30,8 @@ public static function getInfo() { ); } - protected function setUp() { - parent::setUp(); - theme_enable(array('test_theme_twig')); - } - /** - * Ensures Twig template auto reloading can be overridden. + * Ensures Twig template auto reload setting can be overridden. */ function testTwigAutoReloadOverride() { // Enable twig_auto_reload and rebuild the service container. @@ -47,19 +43,49 @@ function testTwigAutoReloadOverride() { } /** - * Ensures Twig engine debugging can be overridden. + * Ensures Twig engine debug setting can be overridden. */ function testTwigDebugOverride() { - variable_set('theme_default', 'test_theme_twig'); - // Enable twig_debug, rebuild the service container, and clear all caches. + // Enable twig_debug and rebuild the service container. $this->settingsSet('twig_debug', TRUE); $this->rebuildContainer(); - $this->resetAll(); + // Check isDebug() via the Twig service container. $this->assertTrue(drupal_container()->get('twig')->isDebug(), 'Debug overridden in Twig service.'); + } + + /** + * Ensures Twig template cache setting can be overridden. + */ + function testTwigCacheOverride() { + theme_enable(array('test_theme_twig')); + variable_set('theme_default', 'test_theme_twig'); + + $cache = array(); + // Prime the theme cache. + foreach (module_implements('theme') as $module) { + _theme_process_registry($cache, $module, 'module', $module, drupal_get_path('module', $module)); + } + + // Load array of Twig templates. + $templates = drupal_find_theme_templates($cache, '.html.twig', drupal_get_path('theme', 'test_theme_twig')); + // Get the template filename and the cache filename for + // theme_test_template_test.html.twig. + $template_filename = $templates['theme_test_template_test']['path'] . '/' . $templates['theme_test_template_test']['template'] . '.html.twig'; + $cache_filename = drupal_container()->get('twig')->getCacheFilename($template_filename); + + // Navigate to the page and make sure the template gets cached. $this->drupalGet('theme-test/template-test'); - $this->assertRaw('', 'Twig debug output found.'); + $this->assertTrue(PhpStorageFactory::get('twig')->exists($cache_filename), 'Cached Twig template found.'); + + // Disable the Twig cache and rebuild the service container. + $this->settingsSet('twig_cache', FALSE); + $this->rebuildContainer(); + + // This should return false after rebuilding the service container. + $new_cache_filename = drupal_container()->get('twig')->getCacheFilename($template_filename); + $this->assertFalse($new_cache_filename, 'Twig environment does not return cache filename after caching is disabled.'); } }