3 namespace Drupal\config\Tests;
5 use Drupal\Core\Config\InstallStorage;
6 use Drupal\Core\Serialization\Yaml;
7 use Drupal\simpletest\InstallerTestBase;
10 * Tests install profile config overrides can not add unmet dependencies.
14 class ConfigInstallProfileUnmetDependenciesTest extends InstallerTestBase {
17 * The installation profile to install.
21 protected $profile = 'testing_config_overrides';
24 * Set to TRUE if the expected exception is thrown.
28 protected $expectedException = FALSE;
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) {
40 mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
43 copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
47 // Add a dependency that can not be met because User is installed before
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));
60 * Override the error method so we can test for the expected exception.
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);
68 if ($group == 'Drupal\Core\Config\UnmetDependenciesException') {
69 $this->expectedException = TRUE;
72 return $this->assert('exception', $message, $group, $caller);
78 protected function setUpSite() {
79 // This step is not reached due to the exception.
84 * Confirms that the installation succeeded.
86 public function testInstalled() {
87 if ($this->expectedException) {
88 $this->pass('Expected Drupal\Core\Config\UnmetDependenciesException exception thrown');
91 $this->fail('Expected Drupal\Core\Config\UnmetDependenciesException exception thrown');
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>');