Mercurial > hg > isophonics-drupal-site
comparison core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\system\Tests\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 Drupal\simpletest\InstallerTestBase; | |
10 use Symfony\Component\HttpFoundation\Request; | |
11 | |
12 /** | |
13 * Tests distribution profile support with existing settings. | |
14 * | |
15 * @group Installer | |
16 */ | |
17 class DistributionProfileExistingSettingsTest extends InstallerTestBase { | |
18 | |
19 /** | |
20 * The distribution profile info. | |
21 * | |
22 * @var array | |
23 */ | |
24 protected $info; | |
25 | |
26 /** | |
27 * {@inheritdoc} | |
28 */ | |
29 protected function setUp() { | |
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 parent::setUp(); | |
75 } | |
76 | |
77 /** | |
78 * {@inheritdoc} | |
79 */ | |
80 protected function setUpLanguage() { | |
81 // Make settings file not writable. | |
82 $filename = $this->siteDirectory . '/settings.php'; | |
83 // Make the settings file read-only. | |
84 // Not using File API; a potential error must trigger a PHP warning. | |
85 chmod($filename, 0444); | |
86 | |
87 // Verify that the distribution name appears. | |
88 $this->assertRaw($this->info['distribution']['name']); | |
89 // Verify that the requested theme is used. | |
90 $this->assertRaw($this->info['distribution']['install']['theme']); | |
91 // Verify that the "Choose profile" step does not appear. | |
92 $this->assertNoText('profile'); | |
93 | |
94 parent::setUpLanguage(); | |
95 } | |
96 | |
97 /** | |
98 * {@inheritdoc} | |
99 */ | |
100 protected function setUpProfile() { | |
101 // This step is skipped, because there is a distribution profile. | |
102 } | |
103 | |
104 /** | |
105 * {@inheritdoc} | |
106 */ | |
107 protected function setUpSettings() { | |
108 // This step should not appear, since settings.php is fully configured | |
109 // already. | |
110 } | |
111 | |
112 /** | |
113 * Confirms that the installation succeeded. | |
114 */ | |
115 public function testInstalled() { | |
116 $this->assertUrl('user/1'); | |
117 $this->assertResponse(200); | |
118 // Confirm that we are logged-in after installation. | |
119 $this->assertText($this->rootUser->getUsername()); | |
120 | |
121 // Confirm that Drupal recognizes this distribution as the current profile. | |
122 $this->assertEqual(\Drupal::installProfile(), 'mydistro'); | |
123 $this->assertNull(Settings::get('install_profile'), 'The install profile has not been written to settings.php.'); | |
124 $this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.'); | |
125 | |
126 $this->rebuildContainer(); | |
127 $this->pass('Container can be rebuilt even though distribution is not written to settings.php.'); | |
128 $this->assertEqual(\Drupal::installProfile(), 'mydistro'); | |
129 } | |
130 | |
131 } |