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