9ec2c767dc850a624ce86683f9330a61be56f5ae
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / Installer / InstallerExistingSettingsMismatchProfileTest.php
1 <?php
2
3 namespace Drupal\FunctionalTests\Installer;
4
5 use Drupal\Core\DrupalKernel;
6 use Drupal\Core\Site\Settings;
7 use Drupal\Core\Database\Database;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11  * Tests install with existing settings.php and a mismatching install profile.
12  *
13  * @group Installer
14  * @group legacy
15  */
16 class InstallerExistingSettingsMismatchProfileTest extends InstallerTestBase {
17
18   /**
19    * {@inheritdoc}
20    *
21    * Configures a preexisting settings.php file without an install_profile
22    * setting before invoking the interactive installer.
23    */
24   protected function prepareEnvironment() {
25     parent::prepareEnvironment();
26     // Pre-configure hash salt.
27     // Any string is valid, so simply use the class name of this test.
28     $this->settings['settings']['hash_salt'] = (object) [
29       'value' => __CLASS__,
30       'required' => TRUE,
31     ];
32
33     // Pre-configure database credentials.
34     $connection_info = Database::getConnectionInfo();
35     unset($connection_info['default']['pdo']);
36     unset($connection_info['default']['init_commands']);
37
38     $this->settings['databases']['default'] = (object) [
39       'value' => $connection_info,
40       'required' => TRUE,
41     ];
42
43     // During interactive install we'll change this to a different profile and
44     // this test will ensure that the new value is written to settings.php.
45     $this->settings['settings']['install_profile'] = (object) [
46       'value' => 'minimal',
47       'required' => TRUE,
48     ];
49
50     // Pre-configure config directories.
51     $this->settings['config_directories'] = [
52       CONFIG_SYNC_DIRECTORY => (object) [
53         'value' => DrupalKernel::findSitePath(Request::createFromGlobals()) . '/files/config_sync',
54         'required' => TRUE,
55       ],
56     ];
57     mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   protected function visitInstaller() {
64     // Provide profile and language in query string to skip these pages.
65     $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=testing');
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   protected function setUpLanguage() {
72     // This step is skipped, because there is a langcode as a query param.
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   protected function setUpProfile() {
79     // This step is skipped, because there is a profile as a query param.
80   }
81
82   /**
83    * {@inheritdoc}
84    */
85   protected function setUpSettings() {
86     // This step should not appear, since settings.php is fully configured
87     // already.
88   }
89
90   /**
91    * Verifies that installation succeeded.
92    *
93    * @expectedDeprecation To access the install profile in Drupal 8 use \Drupal::installProfile() or inject the install_profile container parameter into your service. See https://www.drupal.org/node/2538996
94    */
95   public function testInstaller() {
96     $this->assertUrl('user/1');
97     $this->assertResponse(200);
98     $this->assertEqual('testing', \Drupal::installProfile());
99     $this->assertEqual('testing', Settings::get('install_profile'), 'Profile was correctly changed to testing in Settings.php');
100   }
101
102 }