Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / Installer / DistributionProfileExistingSettingsTest.php
1 <?php
2
3 namespace Drupal\FunctionalTests\Installer;
4
5 use Drupal\Component\Serialization\Yaml;
6 use Drupal\Core\Database\Database;
7 use Drupal\Core\DrupalKernel;
8 use Drupal\Core\Site\Settings;
9 use Symfony\Component\HttpFoundation\Request;
10
11 /**
12  * Tests distribution profile support with existing settings.
13  *
14  * @group Installer
15  */
16 class DistributionProfileExistingSettingsTest extends InstallerTestBase {
17
18   /**
19    * The distribution profile info.
20    *
21    * @var array
22    */
23   protected $info;
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function prepareEnvironment() {
29     parent::prepareEnvironment();
30     $this->info = [
31       'type' => 'profile',
32       'core' => \Drupal::CORE_COMPATIBILITY,
33       'name' => 'Distribution profile',
34       'distribution' => [
35         'name' => 'My Distribution',
36         'install' => [
37           'theme' => 'bartik',
38         ],
39       ],
40     ];
41     // File API functions are not available yet.
42     $path = $this->siteDirectory . '/profiles/mydistro';
43     mkdir($path, 0777, TRUE);
44     file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
45
46     // Pre-configure hash salt.
47     // Any string is valid, so simply use the class name of this test.
48     $this->settings['settings']['hash_salt'] = (object) [
49       'value' => __CLASS__,
50       'required' => TRUE,
51     ];
52
53     // Pre-configure database credentials.
54     $connection_info = Database::getConnectionInfo();
55     unset($connection_info['default']['pdo']);
56     unset($connection_info['default']['init_commands']);
57
58     $this->settings['databases']['default'] = (object) [
59       'value' => $connection_info,
60       'required' => TRUE,
61     ];
62
63     // Use the kernel to find the site path because the site.path service should
64     // not be available at this point in the install process.
65     $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
66     // Pre-configure config directories.
67     $this->settings['config_directories'] = [
68       CONFIG_SYNC_DIRECTORY => (object) [
69         'value' => $site_path . '/files/config_staging',
70         'required' => TRUE,
71       ],
72     ];
73     mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   protected function setUpLanguage() {
80     // Make settings file not writable.
81     $filename = $this->siteDirectory . '/settings.php';
82     // Make the settings file read-only.
83     // Not using File API; a potential error must trigger a PHP warning.
84     chmod($filename, 0444);
85
86     // Verify that the distribution name appears.
87     $this->assertRaw($this->info['distribution']['name']);
88     // Verify that the requested theme is used.
89     $this->assertRaw($this->info['distribution']['install']['theme']);
90     // Verify that the "Choose profile" step does not appear.
91     $this->assertNoText('profile');
92
93     parent::setUpLanguage();
94   }
95
96   /**
97    * {@inheritdoc}
98    */
99   protected function setUpProfile() {
100     // This step is skipped, because there is a distribution profile.
101   }
102
103   /**
104    * {@inheritdoc}
105    */
106   protected function setUpSettings() {
107     // This step should not appear, since settings.php is fully configured
108     // already.
109   }
110
111   /**
112    * Confirms that the installation succeeded.
113    */
114   public function testInstalled() {
115     $this->assertUrl('user/1');
116     $this->assertResponse(200);
117     // Confirm that we are logged-in after installation.
118     $this->assertText($this->rootUser->getUsername());
119
120     // Confirm that Drupal recognizes this distribution as the current profile.
121     $this->assertEqual(\Drupal::installProfile(), 'mydistro');
122     $this->assertArrayNotHasKey('install_profile', Settings::getAll(), 'The install profile has not been written to settings.php.');
123     $this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.');
124
125     $this->rebuildContainer();
126     $this->pass('Container can be rebuilt even though distribution is not written to settings.php.');
127     $this->assertEqual(\Drupal::installProfile(), 'mydistro');
128   }
129
130 }