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

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@17 1 <?php
Chris@17 2
Chris@17 3 namespace Drupal\FunctionalTests\Installer;
Chris@17 4
Chris@17 5 use Drupal\Core\DrupalKernel;
Chris@17 6 use Drupal\Core\Database\Database;
Chris@17 7 use Drupal\Core\Site\Settings;
Chris@17 8 use Symfony\Component\HttpFoundation\Request;
Chris@17 9
Chris@17 10 /**
Chris@17 11 * Tests installer breaks with a profile mismatch and a read-only settings.php.
Chris@17 12 *
Chris@17 13 * @group Installer
Chris@17 14 * @group legacy
Chris@17 15 */
Chris@17 16 class InstallerExistingSettingsReadOnlyMismatchProfileTest extends InstallerTestBase {
Chris@17 17
Chris@17 18 /**
Chris@17 19 * {@inheritdoc}
Chris@17 20 *
Chris@17 21 * Configures a preexisting settings.php file without an install_profile
Chris@17 22 * setting before invoking the interactive installer.
Chris@17 23 */
Chris@17 24 protected function prepareEnvironment() {
Chris@17 25 parent::prepareEnvironment();
Chris@17 26 // Pre-configure hash salt.
Chris@17 27 // Any string is valid, so simply use the class name of this test.
Chris@17 28 $this->settings['settings']['hash_salt'] = (object) [
Chris@17 29 'value' => __CLASS__,
Chris@17 30 'required' => TRUE,
Chris@17 31 ];
Chris@17 32
Chris@17 33 // Pre-configure database credentials.
Chris@17 34 $connection_info = Database::getConnectionInfo();
Chris@17 35 unset($connection_info['default']['pdo']);
Chris@17 36 unset($connection_info['default']['init_commands']);
Chris@17 37
Chris@17 38 $this->settings['databases']['default'] = (object) [
Chris@17 39 'value' => $connection_info,
Chris@17 40 'required' => TRUE,
Chris@17 41 ];
Chris@17 42
Chris@17 43 // During interactive install we'll change this to a different profile and
Chris@17 44 // this test will ensure that the new value is written to settings.php.
Chris@17 45 $this->settings['settings']['install_profile'] = (object) [
Chris@17 46 'value' => 'minimal',
Chris@17 47 'required' => TRUE,
Chris@17 48 ];
Chris@17 49
Chris@17 50 // Pre-configure config directories.
Chris@17 51 $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
Chris@17 52 $this->settings['config_directories'] = [
Chris@17 53 CONFIG_SYNC_DIRECTORY => (object) [
Chris@17 54 'value' => $site_path . '/files/config_staging',
Chris@17 55 'required' => TRUE,
Chris@17 56 ],
Chris@17 57 ];
Chris@17 58 mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
Chris@17 59 }
Chris@17 60
Chris@17 61 /**
Chris@17 62 * {@inheritdoc}
Chris@17 63 */
Chris@17 64 protected function visitInstaller() {
Chris@17 65 // Make settings file not writable. This will break the installer.
Chris@17 66 $filename = $this->siteDirectory . '/settings.php';
Chris@17 67 // Make the settings file read-only.
Chris@17 68 // Not using File API; a potential error must trigger a PHP warning.
Chris@17 69 chmod($filename, 0444);
Chris@17 70
Chris@17 71 $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=testing');
Chris@17 72 }
Chris@17 73
Chris@17 74 /**
Chris@17 75 * {@inheritdoc}
Chris@17 76 */
Chris@17 77 protected function setUpLanguage() {
Chris@17 78 // This step is skipped, because there is a lagcode as a query param.
Chris@17 79 }
Chris@17 80
Chris@17 81 /**
Chris@17 82 * {@inheritdoc}
Chris@17 83 */
Chris@17 84 protected function setUpProfile() {
Chris@17 85 // This step is skipped, because there is a profile as a query param.
Chris@17 86 }
Chris@17 87
Chris@17 88 /**
Chris@17 89 * {@inheritdoc}
Chris@17 90 */
Chris@17 91 protected function setUpSettings() {
Chris@17 92 // This step should not appear, since settings.php is fully configured
Chris@17 93 // already.
Chris@17 94 }
Chris@17 95
Chris@17 96 /**
Chris@17 97 * Verifies that installation succeeded.
Chris@17 98 *
Chris@17 99 * @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
Chris@17 100 */
Chris@17 101 public function testInstalled() {
Chris@17 102 $this->initBrowserOutputFile();
Chris@17 103 $this->htmlOutput(NULL);
Chris@17 104 $this->assertEquals('testing', \Drupal::installProfile());
Chris@17 105 $this->assertEquals('minimal', Settings::get('install_profile'));
Chris@17 106 $this->drupalGet('admin/reports/status');
Chris@17 107 $this->assertSession()->pageTextContains("Drupal 8 no longer uses the \$settings['install_profile'] value in settings.php and it can be removed.");
Chris@17 108 }
Chris@17 109
Chris@17 110 }