Ensures Twig template cache setting can be overridden.
function testTwigCacheOverride() {
$extension = twig_extension();
theme_enable(array(
'test_theme',
));
config('system.theme')
->set('default', 'test_theme')
->save();
$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, $extension, drupal_get_path('theme', 'test_theme'));
// 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'] . $extension;
$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
->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.');
}