Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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   ];
28
29   /**
30    * The theme handler.
31    *
32    * @var \Drupal\Core\Extension\ThemeHandlerInterface
33    */
34   protected $themeHandler;
35
36   /**
37    * A list of all core modules.
38    *
39    * @var string[]
40    */
41   protected $allModules;
42
43   /**
44    * {@inheritdoc}
45    */
46   protected function setUp() {
47     parent::setUp();
48     $this->themeHandler = $this->container->get('theme_handler');
49
50     $this->container->get('theme_installer')->install(['stable']);
51
52     $this->installAllModules();
53   }
54
55   /**
56    * Installs all core modules.
57    */
58   protected function installAllModules() {
59     // Needed for system_rebuild_module_data().
60     include_once $this->root . '/core/modules/system/system.module';
61
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)') {
68         return FALSE;
69       }
70       return TRUE;
71     });
72     $this->allModules = array_keys($all_modules);
73     sort($this->allModules);
74
75     $module_installer = $this->container->get('module_installer');
76     $module_installer->install($this->allModules);
77
78     $this->installConfig(['system', 'user']);
79   }
80
81   /**
82    * Ensures that Stable overrides all relevant core templates.
83    */
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());
87
88     $registry_full = $registry->get();
89
90     foreach ($registry_full as $hook => $info) {
91       if (isset($info['template'])) {
92         // Allow skipping templates.
93         if (in_array($info['template'], $this->templatesToSkip)) {
94           continue;
95         }
96
97         $this->assertEquals('core/themes/stable', $info['theme path'], $info['template'] . '.html.twig overridden in Stable.');
98       }
99     }
100   }
101
102 }