Pull merge.
[yaffs-website] / web / core / modules / config / tests / src / Functional / ConfigInstallProfileUnmetDependenciesTest.php
1 <?php
2
3 namespace Drupal\Tests\config\Functional;
4
5 use Drupal\FunctionalTests\Installer\InstallerTestBase;
6 use Drupal\Core\Config\InstallStorage;
7 use Drupal\Core\Serialization\Yaml;
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    * Contains the expected exception if it is thrown.
25    *
26    * @var \Drupal\Core\Config\UnmetDependenciesException
27    */
28   protected $expectedException = FALSE;
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function prepareEnvironment() {
34     parent::prepareEnvironment();
35     $this->copyTestingOverrides();
36   }
37
38   /**
39    * {@inheritdoc}
40    */
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.
44     try {
45       parent::setUp();
46     }
47     catch (\Exception $exception) {
48       $this->expectedException = $exception;
49     }
50   }
51
52   /**
53    * Copy the testing_config_overrides install profile.
54    *
55    * So we can change the configuration to include a dependency that can not be
56    * met. File API functions are not available yet.
57    */
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) {
64       if ($item->isDir()) {
65         mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
66       }
67       else {
68         copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
69       }
70     }
71
72     // Add a dependency that can not be met because User is installed before
73     // Action.
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));
78   }
79
80   /**
81    * Confirms that the installation succeeded.
82    */
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());
87     }
88     else {
89       $this->fail('Expected Drupal\Core\Config\UnmetDependenciesException exception not thrown');
90     }
91   }
92
93 }