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',
27 'entity-moderation-form'
33 * @var \Drupal\Core\Extension\ThemeHandlerInterface
35 protected $themeHandler;
38 * A list of all core modules.
42 protected $allModules;
47 protected function setUp() {
49 $this->themeHandler = $this->container->get('theme_handler');
51 $this->container->get('theme_installer')->install(['stable']);
53 $this->installAllModules();
57 * Installs all core modules.
59 protected function installAllModules() {
60 // Needed for system_rebuild_module_data().
61 include_once $this->root . '/core/modules/system/system.module';
63 // Enable all core modules.
64 $all_modules = system_rebuild_module_data();
65 $all_modules = array_filter($all_modules, function ($module) {
66 // Filter contrib, hidden, experimental, already enabled modules, and
67 // modules in the Testing package.
68 if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing' || $module->info['package'] == 'Core (Experimental)') {
73 $this->allModules = array_keys($all_modules);
74 sort($this->allModules);
76 $module_installer = $this->container->get('module_installer');
77 $module_installer->install($this->allModules);
79 $this->installConfig(['system', 'user']);
83 * Ensures that Stable overrides all relevant core templates.
85 public function testStableTemplateOverrides() {
86 $registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable');
87 $registry->setThemeManager(\Drupal::theme());
89 $registry_full = $registry->get();
91 foreach ($registry_full as $hook => $info) {
92 if (isset($info['template'])) {
93 // Allow skipping templates.
94 if (in_array($info['template'], $this->templatesToSkip)) {
98 $this->assertEquals('core/themes/stable', $info['theme path'], $info['template'] . '.html.twig overridden in Stable.');