3 namespace Drupal\Tests\config\Functional;
5 use Drupal\FunctionalTests\Installer\InstallerTestBase;
6 use Drupal\Core\Config\InstallStorage;
7 use Drupal\Core\Serialization\Yaml;
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 * Contains the expected exception if it is thrown.
26 * @var \Drupal\Core\Config\UnmetDependenciesException
28 protected $expectedException = FALSE;
33 protected function prepareEnvironment() {
34 parent::prepareEnvironment();
35 $this->copyTestingOverrides();
41 protected function setUp() {
42 // During set up an UnmetDependenciesException should be thrown, which will
43 // be re-thrown by TestHttpClientMiddleware as a standard Exception.
47 catch (\Exception $exception) {
48 $this->expectedException = $exception;
53 * Copy the testing_config_overrides install profile.
55 * So we can change the configuration to include a dependency that can not be
56 * met. File API functions are not available yet.
58 protected function copyTestingOverrides() {
59 $dest = $this->siteDirectory . '/profiles/testing_config_overrides';
60 mkdir($dest, 0777, TRUE);
61 $source = DRUPAL_ROOT . '/core/profiles/testing_config_overrides';
62 $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
63 foreach ($iterator as $item) {
65 mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
68 copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
72 // Add a dependency that can not be met because User is installed before
74 $config_file = $dest . DIRECTORY_SEPARATOR . InstallStorage::CONFIG_INSTALL_DIRECTORY . DIRECTORY_SEPARATOR . 'system.action.user_block_user_action.yml';
75 $action = Yaml::decode(file_get_contents($config_file));
76 $action['dependencies']['module'][] = 'action';
77 file_put_contents($config_file, Yaml::encode($action));
81 * Confirms that the installation succeeded.
83 public function testInstalled() {
84 if ($this->expectedException) {
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());
86 $this->assertContains('Drupal\Core\Config\UnmetDependenciesException', $this->expectedException->getMessage());
89 $this->fail('Expected Drupal\Core\Config\UnmetDependenciesException exception not thrown');