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