annotate core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileBrokenTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
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\Core\DrupalKernel;
Chris@0 6 use Drupal\simpletest\InstallerTestBase;
Chris@0 7 use Drupal\Core\Database\Database;
Chris@0 8 use Symfony\Component\HttpFoundation\Request;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Tests installer breaks with a profile mismatch and a read-only settings.php.
Chris@0 12 *
Chris@0 13 * @group Installer
Chris@0 14 */
Chris@0 15 class InstallerExistingSettingsMismatchProfileBrokenTest extends InstallerTestBase {
Chris@0 16
Chris@0 17 /**
Chris@0 18 * {@inheritdoc}
Chris@0 19 *
Chris@0 20 * Configures a preexisting settings.php file without an install_profile
Chris@0 21 * setting before invoking the interactive installer.
Chris@0 22 */
Chris@0 23 protected function setUp() {
Chris@0 24 // Pre-configure hash salt.
Chris@0 25 // Any string is valid, so simply use the class name of this test.
Chris@0 26 $this->settings['settings']['hash_salt'] = (object) [
Chris@0 27 'value' => __CLASS__,
Chris@0 28 'required' => TRUE,
Chris@0 29 ];
Chris@0 30
Chris@0 31 // Pre-configure database credentials.
Chris@0 32 $connection_info = Database::getConnectionInfo();
Chris@0 33 unset($connection_info['default']['pdo']);
Chris@0 34 unset($connection_info['default']['init_commands']);
Chris@0 35
Chris@0 36 $this->settings['databases']['default'] = (object) [
Chris@0 37 'value' => $connection_info,
Chris@0 38 'required' => TRUE,
Chris@0 39 ];
Chris@0 40
Chris@0 41 // During interactive install we'll change this to a different profile and
Chris@0 42 // this test will ensure that the new value is written to settings.php.
Chris@0 43 $this->settings['settings']['install_profile'] = (object) [
Chris@0 44 'value' => 'minimal',
Chris@0 45 'required' => TRUE,
Chris@0 46 ];
Chris@0 47
Chris@0 48 // Pre-configure config directories.
Chris@0 49 $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
Chris@0 50 $this->settings['config_directories'] = [
Chris@0 51 CONFIG_SYNC_DIRECTORY => (object) [
Chris@0 52 'value' => $site_path . '/files/config_staging',
Chris@0 53 'required' => TRUE,
Chris@0 54 ],
Chris@0 55 ];
Chris@0 56 mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
Chris@0 57
Chris@0 58 parent::setUp();
Chris@0 59 }
Chris@0 60
Chris@0 61 /**
Chris@0 62 * {@inheritdoc}
Chris@0 63 */
Chris@0 64 protected function visitInstaller() {
Chris@0 65 // Make settings file not writable. This will break the installer.
Chris@0 66 $filename = $this->siteDirectory . '/settings.php';
Chris@0 67 // Make the settings file read-only.
Chris@0 68 // Not using File API; a potential error must trigger a PHP warning.
Chris@0 69 chmod($filename, 0444);
Chris@0 70
Chris@0 71 $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=testing');
Chris@0 72 }
Chris@0 73
Chris@0 74 /**
Chris@0 75 * {@inheritdoc}
Chris@0 76 */
Chris@0 77 protected function setUpLanguage() {
Chris@0 78 // This step is skipped, because there is a lagcode as a query param.
Chris@0 79 }
Chris@0 80
Chris@0 81 /**
Chris@0 82 * {@inheritdoc}
Chris@0 83 */
Chris@0 84 protected function setUpProfile() {
Chris@0 85 // This step is skipped, because there is a profile as a query param.
Chris@0 86 }
Chris@0 87
Chris@0 88 /**
Chris@0 89 * {@inheritdoc}
Chris@0 90 */
Chris@0 91 protected function setUpSettings() {
Chris@0 92 // This step should not appear, since settings.php is fully configured
Chris@0 93 // already.
Chris@0 94 }
Chris@0 95
Chris@0 96 protected function setUpSite() {
Chris@0 97 // This step should not appear, since settings.php could not be written.
Chris@0 98 }
Chris@0 99
Chris@0 100 /**
Chris@0 101 * Verifies that installation did not succeed.
Chris@0 102 */
Chris@0 103 public function testBrokenInstaller() {
Chris@0 104 $this->assertTitle('Install profile mismatch | Drupal');
Chris@0 105 $this->assertText("The selected profile testing does not match the install_profile setting, which is minimal. Cannot write updated setting to {$this->siteDirectory}/settings.php.");
Chris@0 106 }
Chris@0 107
Chris@0 108 }