annotate core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php @ 12:7a779792577d

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