Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\config\Tests;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Config\InstallStorage;
|
Chris@0
|
6 use Drupal\Core\Serialization\Yaml;
|
Chris@0
|
7 use Drupal\simpletest\InstallerTestBase;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Tests install profile config overrides can not add unmet dependencies.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group Config
|
Chris@0
|
13 */
|
Chris@0
|
14 class ConfigInstallProfileUnmetDependenciesTest extends InstallerTestBase {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * The installation profile to install.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @var string
|
Chris@0
|
20 */
|
Chris@0
|
21 protected $profile = 'testing_config_overrides';
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * Set to TRUE if the expected exception is thrown.
|
Chris@0
|
25 *
|
Chris@0
|
26 * @var bool
|
Chris@0
|
27 */
|
Chris@0
|
28 protected $expectedException = FALSE;
|
Chris@0
|
29
|
Chris@0
|
30 protected function setUp() {
|
Chris@0
|
31 // Copy the testing_config_overrides install profile so we can change the
|
Chris@0
|
32 // configuration to include a dependency that can not be met. File API
|
Chris@0
|
33 // functions are not available yet.
|
Chris@0
|
34 $dest = $this->siteDirectory . '/profiles/testing_config_overrides';
|
Chris@0
|
35 mkdir($dest, 0777, TRUE);
|
Chris@0
|
36 $source = DRUPAL_ROOT . '/core/profiles/testing_config_overrides';
|
Chris@0
|
37 $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
|
Chris@0
|
38 foreach ($iterator as $item) {
|
Chris@0
|
39 if ($item->isDir()) {
|
Chris@0
|
40 mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
|
Chris@0
|
41 }
|
Chris@0
|
42 else {
|
Chris@0
|
43 copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
|
Chris@0
|
44 }
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@0
|
47 // Add a dependency that can not be met because User is installed before
|
Chris@0
|
48 // Action.
|
Chris@0
|
49 $config_file = $dest . DIRECTORY_SEPARATOR . InstallStorage::CONFIG_INSTALL_DIRECTORY . DIRECTORY_SEPARATOR . 'system.action.user_block_user_action.yml';
|
Chris@0
|
50 $action = Yaml::decode(file_get_contents($config_file));
|
Chris@0
|
51 $action['dependencies']['module'][] = 'action';
|
Chris@0
|
52 file_put_contents($config_file, Yaml::encode($action));
|
Chris@0
|
53
|
Chris@0
|
54 parent::setUp();
|
Chris@0
|
55 }
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * {@inheritdoc}
|
Chris@0
|
59 *
|
Chris@0
|
60 * Override the error method so we can test for the expected exception.
|
Chris@0
|
61 */
|
Chris@0
|
62 protected function error($message = '', $group = 'Other', array $caller = NULL) {
|
Chris@0
|
63 if ($group == 'User notice') {
|
Chris@0
|
64 // Since 'User notice' is set by trigger_error() which is used for debug
|
Chris@0
|
65 // set the message to a status of 'debug'.
|
Chris@0
|
66 return $this->assert('debug', $message, 'Debug', $caller);
|
Chris@0
|
67 }
|
Chris@0
|
68 if ($group == 'Drupal\Core\Config\UnmetDependenciesException') {
|
Chris@0
|
69 $this->expectedException = TRUE;
|
Chris@0
|
70 return FALSE;
|
Chris@0
|
71 }
|
Chris@0
|
72 return $this->assert('exception', $message, $group, $caller);
|
Chris@0
|
73 }
|
Chris@0
|
74
|
Chris@0
|
75 /**
|
Chris@0
|
76 * {@inheritdoc}
|
Chris@0
|
77 */
|
Chris@0
|
78 protected function setUpSite() {
|
Chris@0
|
79 // This step is not reached due to the exception.
|
Chris@0
|
80 }
|
Chris@0
|
81
|
Chris@0
|
82
|
Chris@0
|
83 /**
|
Chris@0
|
84 * Confirms that the installation succeeded.
|
Chris@0
|
85 */
|
Chris@0
|
86 public function testInstalled() {
|
Chris@0
|
87 if ($this->expectedException) {
|
Chris@0
|
88 $this->pass('Expected Drupal\Core\Config\UnmetDependenciesException exception thrown');
|
Chris@0
|
89 }
|
Chris@0
|
90 else {
|
Chris@0
|
91 $this->fail('Expected Drupal\Core\Config\UnmetDependenciesException exception thrown');
|
Chris@0
|
92 }
|
Chris@0
|
93 $this->assertErrorLogged('Configuration objects provided by <em class="placeholder">user</em> have unmet dependencies: <em class="placeholder">system.action.user_block_user_action (action)</em>');
|
Chris@0
|
94 }
|
Chris@0
|
95
|
Chris@0
|
96 }
|