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