Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\KernelTests\Config; | |
4 | |
5 use Drupal\Core\Config\FileStorage; | |
6 use Drupal\Core\Config\InstallStorage; | |
7 use Drupal\Core\Config\StorageInterface; | |
8 use Drupal\KernelTests\AssertConfigTrait; | |
9 use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait; | |
10 use Drupal\KernelTests\KernelTestBase; | |
11 | |
12 /** | |
13 * Tests that the installed config matches the default config. | |
14 * | |
15 * @group Config | |
16 */ | |
17 class DefaultConfigTest extends KernelTestBase { | |
18 | |
19 use AssertConfigTrait; | |
20 use FileSystemModuleDiscoveryDataProviderTrait; | |
21 | |
22 /** | |
23 * {@inheritdoc} | |
24 */ | |
25 protected static $timeLimit = 500; | |
26 | |
27 /** | |
28 * {@inheritdoc} | |
29 */ | |
30 public static $modules = ['system', 'user']; | |
31 | |
32 /** | |
33 * The following config entries are changed on module install. | |
34 * | |
35 * Comparing them does not make sense. | |
36 * | |
37 * @todo Figure out why simpletest.settings is not installed. | |
38 * | |
39 * @var array | |
40 */ | |
41 public static $skippedConfig = [ | |
42 'locale.settings' => ['path: '], | |
43 'syslog.settings' => ['facility: '], | |
44 'simpletest.settings' => TRUE, | |
45 ]; | |
46 | |
47 /** | |
48 * {@inheritdoc} | |
49 */ | |
50 protected function setUp() { | |
51 parent::setUp(); | |
52 | |
53 // @todo ModuleInstaller calls system_rebuild_module_data which is part of | |
54 // system.module, see https://www.drupal.org/node/2208429. | |
55 include_once $this->root . '/core/modules/system/system.module'; | |
56 | |
57 // Set up the state values so we know where to find the files when running | |
58 // drupal_get_filename(). | |
59 // @todo Remove as part of https://www.drupal.org/node/2186491 | |
60 system_rebuild_module_data(); | |
61 } | |
62 | |
63 /** | |
64 * Tests if installed config is equal to the exported config. | |
65 * | |
66 * @dataProvider coreModuleListDataProvider | |
67 */ | |
68 public function testModuleConfig($module) { | |
69 // System and user are required in order to be able to install some of the | |
70 // other modules. Therefore they are put into static::$modules, which though | |
71 // doesn't install config files, so import those config files explicitly. | |
72 switch ($module) { | |
73 case 'system': | |
74 case 'user': | |
75 $this->installConfig([$module]); | |
76 break; | |
77 } | |
78 | |
79 $module_path = drupal_get_path('module', $module) . '/'; | |
80 | |
81 /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */ | |
82 $module_installer = $this->container->get('module_installer'); | |
83 | |
84 // @todo https://www.drupal.org/node/2308745 Rest has an implicit dependency | |
85 // on the Node module remove once solved. | |
86 if (in_array($module, ['rest', 'hal'])) { | |
87 $module_installer->install(['node']); | |
88 } | |
89 | |
90 // Work out any additional modules and themes that need installing to create | |
91 // an optional config. | |
92 $optional_config_storage = new FileStorage($module_path . InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION); | |
93 $modules_to_install = [$module]; | |
94 $themes_to_install = []; | |
95 foreach ($optional_config_storage->listAll() as $config_name) { | |
96 $data = $optional_config_storage->read($config_name); | |
97 if (isset($data['dependencies']['module'])) { | |
98 $modules_to_install = array_merge($modules_to_install, $data['dependencies']['module']); | |
99 } | |
100 if (isset($data['dependencies']['theme'])) { | |
101 $themes_to_install = array_merge($themes_to_install, $data['dependencies']['theme']); | |
102 } | |
103 } | |
104 $module_installer->install(array_unique($modules_to_install)); | |
105 $this->container->get('theme_installer')->install($themes_to_install); | |
106 | |
107 // Test configuration in the module's config/install directory. | |
108 $module_config_storage = new FileStorage($module_path . InstallStorage::CONFIG_INSTALL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION); | |
109 $this->doTestsOnConfigStorage($module_config_storage); | |
110 | |
111 // Test configuration in the module's config/optional directory. | |
112 $this->doTestsOnConfigStorage($optional_config_storage); | |
113 } | |
114 | |
115 /** | |
116 * Tests that default config matches the installed config. | |
117 * | |
118 * @param \Drupal\Core\Config\StorageInterface $default_config_storage | |
119 * The default config storage to test. | |
120 */ | |
121 protected function doTestsOnConfigStorage(StorageInterface $default_config_storage) { | |
122 /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ | |
123 $config_manager = $this->container->get('config.manager'); | |
124 | |
125 // Just connect directly to the config table so we don't need to worry about | |
126 // the cache layer. | |
127 $active_config_storage = $this->container->get('config.storage'); | |
128 | |
129 foreach ($default_config_storage->listAll() as $config_name) { | |
130 if ($active_config_storage->exists($config_name)) { | |
131 // If it is a config entity re-save it. This ensures that any | |
132 // recalculation of dependencies does not cause config change. | |
133 if ($entity_type = $config_manager->getEntityTypeIdByName($config_name)) { | |
134 $entity_storage = $config_manager | |
135 ->getEntityManager() | |
136 ->getStorage($entity_type); | |
137 $id = $entity_storage->getIDFromConfigName($config_name, $entity_storage->getEntityType() | |
138 ->getConfigPrefix()); | |
139 $entity_storage->load($id)->calculateDependencies()->save(); | |
140 } | |
141 $result = $config_manager->diff($default_config_storage, $active_config_storage, $config_name); | |
142 $this->assertConfigDiff($result, $config_name, static::$skippedConfig); | |
143 } | |
144 } | |
145 } | |
146 | |
147 } |