3 namespace Drupal\KernelTests\Core\Theme;
5 use Drupal\Core\Theme\Registry;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests Stable's template overrides.
13 class StableTemplateOverrideTest extends KernelTestBase {
18 public static $modules = ['system', 'user'];
21 * An array of template names to skip, without the extension.
25 protected $templatesToSkip = [
26 'views-form-views-form',
32 * @var \Drupal\Core\Extension\ThemeHandlerInterface
34 protected $themeHandler;
37 * A list of all core modules.
41 protected $allModules;
46 protected function setUp() {
48 $this->themeHandler = $this->container->get('theme_handler');
50 $this->container->get('theme_installer')->install(['stable']);
52 $this->installAllModules();
56 * Installs all core modules.
58 protected function installAllModules() {
59 // Needed for system_rebuild_module_data().
60 include_once $this->root . '/core/modules/system/system.module';
62 // Enable all core modules.
63 $all_modules = system_rebuild_module_data();
64 $all_modules = array_filter($all_modules, function ($module) {
65 // Filter contrib, hidden, experimental, already enabled modules, and
66 // modules in the Testing package.
67 if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing' || $module->info['package'] == 'Core (Experimental)') {
72 $this->allModules = array_keys($all_modules);
73 sort($this->allModules);
75 $module_installer = $this->container->get('module_installer');
76 $module_installer->install($this->allModules);
78 $this->installConfig(['system', 'user']);
82 * Ensures that Stable overrides all relevant core templates.
84 public function testStableTemplateOverrides() {
85 $registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable');
86 $registry->setThemeManager(\Drupal::theme());
88 $registry_full = $registry->get();
90 foreach ($registry_full as $hook => $info) {
91 if (isset($info['template'])) {
92 // Allow skipping templates.
93 if (in_array($info['template'], $this->templatesToSkip)) {
97 $this->assertEquals('core/themes/stable', $info['theme path'], $info['template'] . '.html.twig overridden in Stable.');