Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Theme / StableTemplateOverrideTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Theme;
4
5 use Drupal\Core\Theme\Registry;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests Stable's template overrides.
10  *
11  * @group Theme
12  */
13 class StableTemplateOverrideTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['system', 'user'];
19
20   /**
21    * An array of template names to skip, without the extension.
22    *
23    * @var string[]
24    */
25   protected $templatesToSkip = [
26     'views-form-views-form',
27     'entity-moderation-form'
28   ];
29
30   /**
31    * The theme handler.
32    *
33    * @var \Drupal\Core\Extension\ThemeHandlerInterface
34    */
35   protected $themeHandler;
36
37   /**
38    * A list of all core modules.
39    *
40    * @var string[]
41    */
42   protected $allModules;
43
44   /**
45    * {@inheritdoc}
46    */
47   protected function setUp() {
48     parent::setUp();
49     $this->themeHandler = $this->container->get('theme_handler');
50
51     $this->container->get('theme_installer')->install(['stable']);
52
53     $this->installAllModules();
54   }
55
56   /**
57    * Installs all core modules.
58    */
59   protected function installAllModules() {
60     // Needed for system_rebuild_module_data().
61     include_once $this->root . '/core/modules/system/system.module';
62
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)') {
69         return FALSE;
70       }
71       return TRUE;
72     });
73     $this->allModules = array_keys($all_modules);
74     sort($this->allModules);
75
76     $module_installer = $this->container->get('module_installer');
77     $module_installer->install($this->allModules);
78
79     $this->installConfig(['system', 'user']);
80   }
81
82   /**
83    * Ensures that Stable overrides all relevant core templates.
84    */
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());
88
89     $registry_full = $registry->get();
90
91     foreach ($registry_full as $hook => $info) {
92       if (isset($info['template'])) {
93         // Allow skipping templates.
94         if (in_array($info['template'], $this->templatesToSkip)) {
95           continue;
96         }
97
98         $this->assertEquals('core/themes/stable', $info['theme path'], $info['template'] . '.html.twig overridden in Stable.');
99       }
100     }
101   }
102
103 }