diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 369fdfc..9013e7d 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2438,6 +2438,8 @@ function drupal_fast_404() { * Returns TRUE if a Drupal installation is currently being attempted. */ function drupal_installation_attempted() { + return isset($GLOBALS['install_state']); + // @todo Entirely incompatible with non-interactive installer invoked from SimpleTest. return defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install'; } diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 37b3281..3a3937c 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -251,14 +251,6 @@ function install_begin_request(&$install_state) { drupal_override_server_variables($install_state['server']); } - // The user agent header is used to pass a database prefix in the request when - // running tests. However, for security reasons, it is imperative that no - // installation be permitted using such a prefix. - if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) { - header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); - exit; - } - drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); // This must go after drupal_bootstrap(), which unsets globals! @@ -1296,7 +1288,7 @@ function install_select_language(&$install_state) { } // One language, but not an interactive installation. Assume the user // knows what he is doing. - $langcode = current($files); + $file = current($files); $install_state['parameters']['langcode'] = $file->langcode; return; } diff --git a/core/includes/install.inc b/core/includes/install.inc index 72adf1c..4a2d2df 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -94,10 +94,10 @@ function drupal_load_updates() { * @see install_profile_info() */ function drupal_install_profile_distribution_name() { + global $install_state; // During installation, the profile information is stored in the global // installation state (it might not be saved anywhere yet). - if (drupal_installation_attempted()) { - global $install_state; + if (isset($install_state['profile_info']['distribution_name'])) { return $install_state['profile_info']['distribution_name']; } // At all other times, we load the profile via standard methods. diff --git a/core/modules/simpletest/drupal_web_test_case.php b/core/modules/simpletest/drupal_web_test_case.php index 5d868a2..10f4431 100644 --- a/core/modules/simpletest/drupal_web_test_case.php +++ b/core/modules/simpletest/drupal_web_test_case.php @@ -1319,16 +1319,9 @@ class DrupalWebTestCase extends DrupalTestCase { $this->originalProfile = drupal_get_profile(); $clean_url_original = variable_get('clean_url', 0); - // Set to English to prevent exceptions from utf8_truncate() from t() - // during install if the current language is not 'en'. - // The following array/object conversion is copied from language_default(). - $language = (object) array( - 'langcode' => 'en', - 'name' => 'English', - 'direction' => 0, - 'enabled' => 1, - 'weight' => 0, - ); + // Backup current user. + $this->originalUser = $user; + drupal_save_session(FALSE); // Save and clean shutdown callbacks array because it static cached and // will be changed by the test run. If we don't, then it will contain @@ -1373,12 +1366,52 @@ class DrupalWebTestCase extends DrupalTestCase { // the test's profile as a module. Without this, the installation profile of // the parent site (executing the test) is registered, and the test // profile's hook_install() and other hook implementations are never invoked. - $conf['install_profile'] = $this->profile; - - include_once DRUPAL_ROOT . '/core/includes/install.inc'; - drupal_install_system(); - - $this->preloadRegistry(); + // @todo Double-check this. +// $conf['install_profile'] = $this->profile; + + // Run the Drupal installer non-interactively. + // @see install.php, install.core.inc + require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; + $this->root_user = (object) array( + 'name' => 'admin', + 'mail' => 'admin@example.com', + 'pass_raw' => $this->randomName(), + ); + $settings = array( + 'parameters' => array( + 'profile' => $this->profile, + 'langcode' => 'en', + ), + 'forms' => array( + 'install_settings_form' => array( + 'driver' => $connection_info['default']['driver'], + 'username' => $connection_info['default']['username'], + 'host' => $connection_info['default']['host'], + 'port' => $connection_info['default']['port'], + 'password' => $connection_info['default']['password'], + 'database' => $connection_info['default']['database'], + 'prefix' => $connection_info['default']['prefix'], + ), + 'install_configure_form' => array( + 'site_name' => 'Drupal', + 'site_mail' => 'simpletest@example.com', + 'account' => array( + 'name' => $this->root_user->name, + 'mail' => $this->root_user->mail, + 'pass' => array( + 'pass1' => $this->root_user->pass_raw, + 'pass2' => $this->root_user->pass_raw, + ), + ), + 'update_status_module' => array( + 1 => FALSE, + 2 => FALSE, + ), + 'clean_url' => $clean_url_original, + ), + ), + ); + install_drupal($settings); // Set path variables. variable_set('file_public_path', $public_files_directory); @@ -1411,31 +1444,15 @@ class DrupalWebTestCase extends DrupalTestCase { $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules)))); } - // Run the profile tasks. - $install_profile_module_exists = db_query("SELECT 1 FROM {system} WHERE type = 'module' AND name = :name", array( - ':name' => $this->profile, - ))->fetchField(); - if ($install_profile_module_exists) { - module_enable(array($this->profile), FALSE); - } - // Reset/rebuild all data structures after enabling the modules. $this->resetAll(); - // Run cron once in that environment, as install.php does at the end of - // the installation process. - drupal_cron_run(); - // Log in with a clean $user. - $this->originalUser = $user; - drupal_save_session(FALSE); $user = user_load(1); // Restore necessary variables. - variable_set('install_task', 'done'); - variable_set('clean_url', $clean_url_original); - variable_set('site_mail', 'simpletest@example.com'); variable_set('date_default_timezone', date_default_timezone_get()); + // Set up English language. unset($GLOBALS['conf']['language_default']); $language_interface = language_default();