annotate core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php @ 19:fa3358dc1485 tip

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