comparison core/modules/config/tests/src/Functional/ConfigInstallProfileOverrideTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\config\Functional;
4
5 use Drupal\Component\Utility\Crypt;
6 use Drupal\Core\Config\InstallStorage;
7 use Drupal\Tests\BrowserTestBase;
8 use Drupal\Core\Config\FileStorage;
9 use Drupal\system\Entity\Action;
10 use Drupal\tour\Entity\Tour;
11
12 /**
13 * Tests installation and removal of configuration objects in install, disable
14 * and uninstall functionality.
15 *
16 * @group config
17 */
18 class ConfigInstallProfileOverrideTest extends BrowserTestBase {
19
20 /**
21 * The profile to install as a basis for testing.
22 *
23 * @var string
24 */
25 protected $profile = 'testing_config_overrides';
26
27
28 /**
29 * Tests install profile config changes.
30 */
31 public function testInstallProfileConfigOverwrite() {
32 $config_name = 'system.cron';
33 // The expected configuration from the system module.
34 $expected_original_data = [
35 'threshold' => [
36 'requirements_warning' => 172800,
37 'requirements_error' => 1209600,
38 ],
39 'logging' => 1,
40 ];
41 // The expected active configuration altered by the install profile.
42 $expected_profile_data = [
43 'threshold' => [
44 'requirements_warning' => 259200,
45 'requirements_error' => 1209600,
46 ],
47 'logging' => 1,
48 ];
49 $expected_profile_data['_core']['default_config_hash'] = Crypt::hashBase64(serialize($expected_profile_data));
50
51 // Verify that the original data matches. We have to read the module config
52 // file directly, because the install profile default system.cron.yml
53 // configuration file was used to create the active configuration.
54 $config_dir = drupal_get_path('module', 'system') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
55 $this->assertTrue(is_dir($config_dir));
56 $source_storage = new FileStorage($config_dir);
57 $data = $source_storage->read($config_name);
58 $this->assertIdentical($data, $expected_original_data);
59
60 // Verify that active configuration matches the expected data, which was
61 // created from the testing install profile's system.cron.yml file.
62 $config = $this->config($config_name);
63 $this->assertIdentical($config->get(), $expected_profile_data);
64
65 // Ensure that the configuration entity has the expected dependencies and
66 // overrides.
67 $action = Action::load('user_block_user_action');
68 $this->assertEqual($action->label(), 'Overridden block the selected user(s)');
69 $action = Action::load('user_cancel_user_action');
70 $this->assertEqual($action->label(), 'Cancel the selected user account(s)', 'Default configuration that is not overridden is not affected.');
71
72 // Ensure that optional configuration can be overridden.
73 $tour = Tour::load('language');
74 $this->assertEqual(count($tour->getTips()), 1, 'Optional configuration can be overridden. The language tour only has one tip');
75 $tour = Tour::load('language-add');
76 $this->assertEqual(count($tour->getTips()), 3, 'Optional configuration that is not overridden is not affected.');
77
78 // Ensure that optional configuration from a profile is created if
79 // dependencies are met.
80 $this->assertEqual(Tour::load('testing_config_overrides')->label(), 'Config override test');
81
82 // Ensure that optional configuration from a profile is not created if
83 // dependencies are not met. Cannot use the entity system since the entity
84 // type does not exist.
85 $optional_dir = drupal_get_path('module', 'testing_config_overrides') . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
86 $optional_storage = new FileStorage($optional_dir);
87 foreach (['config_test.dynamic.dotted.default', 'config_test.dynamic.override', 'config_test.dynamic.override_unmet'] as $id) {
88 $this->assertTrue(\Drupal::config($id)->isNew(), "The config_test entity $id contained in the profile's optional directory does not exist.");
89 // Make that we don't get false positives from the assertion above.
90 $this->assertTrue($optional_storage->exists($id), "The config_test entity $id does exist in the profile's optional directory.");
91 }
92
93 // Install the config_test module and ensure that the override from the
94 // install profile is used. Optional configuration can override
95 // configuration in a modules config/install directory.
96 $this->container->get('module_installer')->install(['config_test']);
97 $this->rebuildContainer();
98 $config_test_storage = \Drupal::entityManager()->getStorage('config_test');
99 $this->assertEqual($config_test_storage->load('dotted.default')->label(), 'Default install profile override', 'The config_test entity is overridden by the profile optional configuration.');
100 // Test that override of optional configuration does work.
101 $this->assertEqual($config_test_storage->load('override')->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration.');
102 // Test that override of optional configuration which introduces an unmet
103 // dependency does not get created.
104 $this->assertNull($config_test_storage->load('override_unmet'), 'The optional config_test entity with unmet dependencies is not created.');
105 $this->assertNull($config_test_storage->load('completely_new'), 'The completely new optional config_test entity with unmet dependencies is not created.');
106
107 // Installing dblog creates the optional configuration.
108 $this->container->get('module_installer')->install(['dblog']);
109 $this->rebuildContainer();
110 $this->assertEqual($config_test_storage->load('override_unmet')->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration and is installed when its dependencies are met.');
111 $this->assertEqual($config_test_storage->load('completely_new')->label(), 'Completely new optional configuration', 'The optional config_test entity is provided by the profile optional configuration and is installed when its dependencies are met.');
112 }
113
114 }