/** * Installs Atrium instead of Drupal * * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ protected function setUp() { global $db_prefix, $user, $language, $profile, $install_locale; // $language (Drupal 6). // Store necessary current values before switching to prefixed database. $this->originalPrefix = $db_prefix; $this->originalLanguage = clone $language; $clean_url_original = variable_get('clean_url', 0); // Must reset locale here, since schema calls t(). (Drupal 6) if (module_exists('locale')) { $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''); locale(NULL, NULL, TRUE); } // Generate temporary prefixed database to ensure that tests have a clean starting point. // $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); $db_prefix = 'simpletest' . mt_rand(1000, 1000000); $install_locale = $this->install_locale; $profile = $this->install_profile; // include_once DRUPAL_ROOT . '/includes/install.inc'; include_once './includes/install.inc'; drupal_install_system(); // $this->preloadRegistry(); // Set up theme system for the maintenance page. // Otherwise we have trouble: https://ds.openatrium.com/dsi/node/18426#comment-38118 // @todo simpletest module patch drupal_maintenance_theme(); // Add the specified modules to the list of modules in the default profile. $args = func_get_args(); // $modules = array_unique(array_merge(drupal_get_profile_modules('default', 'en'), $args)); $modules = array_unique(array_merge(drupal_verify_profile($this->install_profile, $this->install_locale), $args)); // drupal_install_modules($modules, TRUE); drupal_install_modules($modules); // Because the schema is static cached, we need to flush // it between each run. If we don't, then it will contain // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); if ($this->install_profile == 'openatrium') { // Download and import translation if needed if ($this->install_locale != 'en') { $this->installLanguage($this->install_locale); } // Install more modules $modules = _openatrium_atrium_modules(); drupal_install_modules($modules); // Configure intranet // $profile_tasks = $this->install_profile . '_profile_tasks'; _openatrium_intranet_configure(); _openatrium_intranet_configure_check(); variable_set('atrium_install', 1); // Clear views cache before rebuilding menu tree. Requires patch // [patch_here] to Views, as new modules have been included and // default views need to be re-detected. module_exists('views') ? views_get_all_views(TRUE) : TRUE; menu_rebuild(); } _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); user_access(NULL, NULL, TRUE); // Drupal 6. // Log in with a clean $user. $this->originalUser = $user; // drupal_save_session(FALSE); // $user = user_load(1); session_save_session(FALSE); $user = user_load(array('uid' => 1)); // Restore necessary variables. variable_set('install_profile', $this->install_profile); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); variable_set('site_mail', '*****@*****.**'); // Use temporary files directory with the same prefix as database. $this->originalFileDirectory = file_directory_path(); variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix); $directory = file_directory_path(); // Create the files directory. file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); set_time_limit($this->timeLimit); }
/** * The Drupal installation happens in a series of steps. We begin by verifying * that the current environment meets our minimum requirements. We then go * on to verify that settings.php is properly configured. From there we * connect to the configured database and verify that it meets our minimum * requirements. Finally we can allow the user to select an installation * profile and complete the installation process. * * @param $phase * The installation phase we should proceed to. */ function install_main() { require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); // 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; } // This must go after drupal_bootstrap(), which unsets globals! global $profile, $install_locale, $conf; require_once './modules/system/system.install'; require_once './includes/file.inc'; // Ensure correct page headers are sent (e.g. caching) drupal_page_header(); // Set up $language, so t() caller functions will still work. drupal_init_language(); // Load module basics (needed for hook invokes). include_once './includes/module.inc'; $module_list['system']['filename'] = 'modules/system/system.module'; $module_list['filter']['filename'] = 'modules/filter/filter.module'; module_list(TRUE, FALSE, FALSE, $module_list); drupal_load('module', 'system'); drupal_load('module', 'filter'); // Install profile chosen, set the global immediately. // This needs to be done before the theme cache gets // initialized in drupal_maintenance_theme(). if (!empty($_GET['profile'])) { $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']); } // Set up theme system for the maintenance page. drupal_maintenance_theme(); // Check existing settings.php. $verify = install_verify_settings(); if ($verify) { // Since we have a database connection, we use the normal cache system. // This is important, as the installer calls into the Drupal system for // the clean URL checks, so we should maintain the cache properly. require_once './includes/cache.inc'; $conf['cache_inc'] = './includes/cache.inc'; // Establish a connection to the database. require_once './includes/database.inc'; db_set_active(); // Check if Drupal is installed. $task = install_verify_drupal(); if ($task == 'done') { install_already_done_error(); } } else { // Since no persistent storage is available yet, and functions that check // for cached data will fail, we temporarily replace the normal cache // system with a stubbed-out version that short-circuits the actual // caching process and avoids any errors. require_once './includes/cache-install.inc'; $conf['cache_inc'] = './includes/cache-install.inc'; $task = NULL; } // No profile was passed in GET, ask the user. if (empty($_GET['profile'])) { if ($profile = install_select_profile()) { install_goto("install.php?profile={$profile}"); } else { install_no_profile_error(); } } // Load the profile. require_once "./profiles/{$profile}/{$profile}.profile"; // Locale selection if (!empty($_GET['locale'])) { $install_locale = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $_GET['locale']); } elseif (($install_locale = install_select_locale($profile)) !== FALSE) { install_goto("install.php?profile={$profile}&locale={$install_locale}"); } // Tasks come after the database is set up if (!$task) { global $db_url; if (!$verify && !empty($db_url)) { // Do not install over a configured settings.php. install_already_done_error(); } // Check the installation requirements for Drupal and this profile. install_check_requirements($profile, $verify); // Verify existence of all required modules. $modules = drupal_verify_profile($profile, $install_locale); // If any error messages are set now, it means a requirement problem. $messages = drupal_set_message(); if (!empty($messages['error'])) { install_task_list('requirements'); drupal_set_title(st('Requirements problem')); print theme('install_page', ''); exit; } // Change the settings.php information if verification failed earlier. // Note: will trigger a redirect if database credentials change. if (!$verify) { install_change_settings($profile, $install_locale); } // Install system.module. drupal_install_system(); // Save the list of other modules to install for the 'profile-install' // task. variable_set() can be used now that system.module is installed // and drupal is bootstrapped. variable_set('install_profile_modules', array_diff($modules, array('system'))); } // The database is set up, turn to further tasks. install_tasks($profile, $task); }
/** * Sets up a Drupal site for running functional and integration tests. * * Generates a random database prefix and installs Drupal with the specified * installation profile in DrupalWebTestCase::$profile into the * prefixed database. Afterwards, installs any additional modules specified by * the test. * * After installation all caches are flushed and several configuration values * are reset to the values of the parent site executing the test, since the * default values may be incompatible with the environment in which tests are * being executed. * * @param ... * List of modules to enable for the duration of the test. This can be * either a single array or a variable number of string arguments. * * @see DrupalWebTestCase::prepareDatabasePrefix() * @see DrupalWebTestCase::changeDatabasePrefix() * @see DrupalWebTestCase::prepareEnvironment() */ protected function setUp() { global $user, $language, $conf; // Create the database prefix for this test. $this->prepareDatabasePrefix(); // Prepare the environment for running tests. $this->prepareEnvironment(); if (!$this->setupEnvironment) { return FALSE; } // Reset all statics and variables to perform tests in a clean environment. $conf = array(); drupal_static_reset(); // Change the database prefix. // All static variables need to be reset before the database prefix is // changed, since DrupalCacheArray implementations attempt to // write back to persistent caches when they are destructed. $this->changeDatabasePrefix(); if (!$this->setupDatabasePrefix) { return FALSE; } // Preset the 'install_profile' system variable, so the first call into // system_rebuild_module_data() (in drupal_install_system()) will register // 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; // Perform the actual Drupal installation. include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_install_system(); $this->preloadRegistry(); // Set path variables. variable_set('file_public_path', $this->public_files_directory); variable_set('file_private_path', $this->private_files_directory); variable_set('file_temporary_path', $this->temp_files_directory); // Set the 'simpletest_parent_profile' variable to add the parent profile's // search path to the child site's search paths. // @see drupal_system_listing() // @todo This may need to be primed like 'install_profile' above. variable_set('simpletest_parent_profile', $this->originalProfile); // Include the testing profile. variable_set('install_profile', $this->profile); $profile_details = install_profile_info($this->profile, 'en'); // Install the modules specified by the testing profile. module_enable($profile_details['dependencies'], FALSE); // Install modules needed for this test. This could have been passed in as // either a single array argument or a variable number of string arguments. // @todo Remove this compatibility layer in Drupal 8, and only accept // $modules as a single array argument. $modules = func_get_args(); if (isset($modules[0]) && is_array($modules[0])) { $modules = $modules[0]; } if ($modules) { $success = module_enable($modules, TRUE); $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(); // Ensure that the session is not written to the new environment and replace // the global $user session with uid 1 from the new test site. drupal_save_session(FALSE); // Login as uid 1. $user = user_load(1); // Restore necessary variables. variable_set('install_task', 'done'); variable_set('clean_url', $this->originalCleanUrl); variable_set('site_mail', '*****@*****.**'); variable_set('date_default_timezone', date_default_timezone_get()); // Set up English language. unset($conf['language_default']); $language = language_default(); // Use the test mail class instead of the default mail handler class. variable_set('mail_system', array('default-system' => 'TestingMailSystem')); drupal_set_time_limit($this->timeLimit); $this->setup = TRUE; }
/** * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. This can be * either a single array or a variable number of string arguments. */ protected function setUp() { global $user, $language, $conf; // Generate a temporary prefixed database to ensure that tests have a clean starting point. $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000); db_update('simpletest_test_id')->fields(array('last_prefix' => $this->databasePrefix))->condition('test_id', $this->testId)->execute(); // Clone the current connection and replace the current prefix. $connection_info = Database::getConnectionInfo('default'); Database::renameConnection('default', 'simpletest_original_default'); foreach ($connection_info as $target => $value) { $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix); } Database::addConnectionInfo('default', 'default', $connection_info['default']); // Store necessary current values before switching to prefixed database. $this->originalLanguage = $language; $this->originalLanguageDefault = variable_get('language_default'); $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files'); $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('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''); // 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 // callbacks from both environments. So testing environment will try // to call handlers from original environment. $callbacks =& drupal_register_shutdown_function(); $this->originalShutdownCallbacks = $callbacks; $callbacks = array(); // Create test directory ahead of installation so fatal errors and debug // information can be logged during installation process. // Use temporary files directory with the same prefix as the database. $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10); $private_files_directory = $public_files_directory . '/private'; $temp_files_directory = $private_files_directory . '/temp'; // Create the directories file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY); file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY); $this->generatedTestFiles = FALSE; // Log fatal errors. ini_set('log_errors', 1); ini_set('error_log', $public_files_directory . '/error.log'); // Reset all statics and variables to perform tests in a clean environment. $conf = array(); drupal_static_reset(); // Set the test information for use in other parts of Drupal. $test_info =& $GLOBALS['drupal_test_info']; $test_info['test_run_id'] = $this->databasePrefix; $test_info['in_child_site'] = FALSE; include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_install_system(); $this->preloadRegistry(); // Set path variables. variable_set('file_public_path', $public_files_directory); variable_set('file_private_path', $private_files_directory); variable_set('file_temporary_path', $temp_files_directory); // Include the testing profile. variable_set('install_profile', $this->profile); $profile_details = install_profile_info($this->profile, 'en'); // Install the modules specified by the testing profile. module_enable($profile_details['dependencies'], FALSE); // Install modules needed for this test. This could have been passed in as // either a single array argument or a variable number of string arguments. // @todo Remove this compatibility layer in Drupal 8, and only accept // $modules as a single array argument. $modules = func_get_args(); if (isset($modules[0]) && is_array($modules[0])) { $modules = $modules[0]; } if ($modules) { $success = module_enable($modules, TRUE); $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', '*****@*****.**'); variable_set('date_default_timezone', date_default_timezone_get()); // Set up English language. unset($GLOBALS['conf']['language_default']); $language = language_default(); // Use the test mail class instead of the default mail handler class. variable_set('mail_system', array('default-system' => 'TestingMailSystem')); drupal_set_time_limit($this->timeLimit); }
/** * Generates a random database prefix and runs the install scripts on the prefixed database. * After installation many caches are flushed and the internal browser is setup so that the page * requests will run on the new prefix. A temporary files directory is created with the same name * as the database prefix. * * @param ... List modules to enable. */ function setUp() { global $db_prefix, $simpletest_ua_key; if ($simpletest_ua_key) { $this->db_prefix_original = $db_prefix; $clean_url_original = variable_get('clean_url', 0); $db_prefix = 'simpletest' . mt_rand(1000, 1000000); include_once './includes/install.inc'; drupal_install_system(); $modules = array_unique(array_merge(func_get_args(), drupal_verify_profile('default', 'en'))); drupal_install_modules($modules); $this->_modules = drupal_map_assoc($modules); $this->_modules['system'] = 'system'; $task = 'profile'; default_profile_tasks($task, ''); menu_rebuild(); actions_synchronize(); _drupal_flush_css_js(); variable_set('install_profile', 'default'); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); // Use temporary files directory with the same prefix as database. $this->original_file_directory = file_directory_path(); variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix); file_check_directory(file_directory_path(), TRUE); // Create the files directory. } parent::setUp(); }
/** * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ protected function setUp() { global $db_prefix, $user, $language; // Store necessary current values before switching to prefixed database. $this->originalLanguage = $language; $this->originalLanguageDefault = variable_get('language_default'); $this->originalPrefix = $db_prefix; $this->originalFileDirectory = file_directory_path(); $this->originalProfile = drupal_get_profile(); $clean_url_original = variable_get('clean_url', 0); // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix_new = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); db_update('simpletest_test_id')->fields(array('last_prefix' => $db_prefix_new))->condition('test_id', $this->testId)->execute(); $db_prefix = $db_prefix_new; // Create test directory ahead of installation so fatal errors and debug // information can be logged during installation process. // Use temporary files directory with the same prefix as the database. $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10); $private_files_directory = $public_files_directory . '/private'; $temp_files_directory = $private_files_directory . '/temp'; // Create the directories file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY); file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY); $this->generatedTestFiles = FALSE; // Log fatal errors. ini_set('log_errors', 1); ini_set('error_log', $public_files_directory . '/error.log'); // Reset all statics so that test is performed with a clean environment. drupal_static_reset(); include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_install_system(); $this->preloadRegistry(); // Include the default profile variable_set('install_profile', 'standard'); $profile_details = install_profile_info('standard', 'en'); // Install the modules specified by the default profile. drupal_install_modules($profile_details['dependencies'], TRUE); drupal_static_reset('_node_types_build'); if ($modules = func_get_args()) { // Install modules needed for this test. drupal_install_modules($modules, TRUE); } // Because the schema is static cached, we need to flush // it between each run. If we don't, then it will contain // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); // Run default profile tasks. $install_state = array(); drupal_install_modules(array('standard'), TRUE); // Rebuild caches. node_types_rebuild(); actions_synchronize(); _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); // 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', '*****@*****.**'); // Set up English language. unset($GLOBALS['conf']['language_default']); $language = language_default(); // Set path variables variable_set('file_public_path', $public_files_directory); variable_set('file_private_path', $private_files_directory); variable_set('file_temporary_path', $temp_files_directory); // Use the test mail class instead of the default mail handler class. variable_set('mail_system', array('default-system' => 'TestingMailSystem')); drupal_set_time_limit($this->timeLimit); }
/** * Installation task; install the Drupal system module. * * @param $install_state * An array of information about the current installation state. */ function install_system_module(&$install_state) { // Install system.module. drupal_install_system(); // Save the list of other modules to install for the upcoming tasks. // variable_set() can be used now that system.module is installed and // Drupal is bootstrapped. $modules = $install_state['profile_info']['dependencies']; // The install profile is also a module, which needs to be installed // after all the dependencies have been installed. $modules[] = drupal_get_profile(); variable_set('install_profile_modules', array_diff($modules, array('system'))); $install_state['database_tables_exist'] = TRUE; }
/** * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ protected function setUp() { global $db_prefix; // Store necessary current values before switching to prefixed database. $this->originalPrefix = $db_prefix; $clean_url_original = variable_get('clean_url', 0); // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix = Database::getActiveConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_install_system(); $this->preloadRegistry(); // Add the specified modules to the list of modules in the default profile. $args = func_get_args(); $modules = array_unique(array_merge(drupal_get_profile_modules('default', 'en'), $args)); drupal_install_modules($modules); // Because the schema is static cached, we need to flush // it between each run. If we don't, then it will contain // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); // Run default profile tasks. $task = 'profile'; default_profile_tasks($task, ''); // Rebuild caches. actions_synchronize(); _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); // Restore necessary variables. variable_set('install_profile', 'default'); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); variable_set('site_mail', '*****@*****.**'); // Use temporary files directory with the same prefix as database. $this->originalFileDirectory = file_directory_path(); variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix); $directory = file_directory_path(); file_check_directory($directory, FILE_CREATE_DIRECTORY); // Create the files directory. }
/** * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ protected function setUp() { global $db_prefix, $user, $language; // Store necessary current values before switching to prefixed database. $this->originalLanguage = $language; $this->originalLanguageDefault = variable_get('language_default'); $this->originalPrefix = $db_prefix; $this->originalFileDirectory = file_directory_path(); $clean_url_original = variable_get('clean_url', 0); // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_install_system(); $this->preloadRegistry(); // Add the specified modules to the list of modules in the default profile. // Install the modules specified by the default profile. $core_modules = drupal_get_profile_modules('default', 'en'); drupal_install_modules($core_modules, TRUE); node_type_clear(); // Install additional modules one at a time in order to make sure that the // list of modules is updated between each module's installation. $modules = func_get_args(); foreach ($modules as $module) { drupal_install_modules(array($module), TRUE); } // Because the schema is static cached, we need to flush // it between each run. If we don't, then it will contain // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); // Run default profile tasks. $task = 'profile'; default_profile_tasks($task, ''); // Rebuild caches. node_types_rebuild(); actions_synchronize(); _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); // Log in with a clean $user. $this->originalUser = $user; drupal_save_session(FALSE); $user = user_load(1); // Restore necessary variables. variable_set('install_profile', 'default'); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); variable_set('site_mail', '*****@*****.**'); // Set up English language. unset($GLOBALS['conf']['language_default']); $language = language_default(); // Make sure our drupal_mail_wrapper function is called instead of the // default mail handler. variable_set('smtp_library', drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php'); // Use temporary files directory with the same prefix as database. variable_set('file_directory_path', $this->originalFileDirectory . '/' . $db_prefix); $directory = file_directory_path(); // Create the files directory. file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); set_time_limit($this->timeLimit); }
/** * Perform Drupal installation. */ protected function setUpInstall(array $modules, $public_files_directory, $private_files_directory, $temp_files_directory) { include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_install_system(); $this->preloadRegistry(); // Set path variables. variable_set('file_public_path', $public_files_directory); variable_set('file_private_path', $private_files_directory); variable_set('file_temporary_path', $temp_files_directory); // Include the testing profile. variable_set('install_profile', $this->profile); $profile_details = install_profile_info($this->profile, 'en'); // Install the modules specified by the testing profile. module_enable($profile_details['dependencies'], FALSE); // Install modules needed for this test. This could have been passed in as // either a single array argument or a variable number of string arguments. // @todo Remove this compatibility layer in Drupal 8, and only accept // $modules as a single array argument. if (isset($modules[0]) && is_array($modules[0])) { $modules = $modules[0]; } if ($modules) { module_enable($modules, TRUE); } // 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); }
/** * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ protected function setUp() { global $db_prefix, $user, $language; // Store necessary current values before switching to prefixed database. $this->originalLanguage = $language; // $this->originalLanguageDefault = variable_get('language_default'); $this->originalPrefix = $db_prefix; $this->originalFileDirectory = file_directory_path(); // $this->originalProfile = drupal_get_profile(); $clean_url_original = variable_get('clean_url', 0); // Must reset locale here, since schema calls t(). (Drupal 6) if (module_exists('locale')) { $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''); locale(NULL, NULL, TRUE); } // Generate temporary prefixed database to ensure that tests have a clean starting point. // $db_prefix_new = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); $db_prefix_new = $db_prefix . 'simpletest' . mt_rand(1000, 1000000); // Workaround to insure we init the theme layer before going into prefixed // environment. (Drupal 6) $this->pass(t('Starting run with db_prefix %prefix', array('%prefix' => $db_prefix_new)), 'System'); // db_update('simpletest_test_id') // ->fields(array('last_prefix' => $db_prefix_new)) // ->condition('test_id', $this->testId) // ->execute(); db_query("UPDATE {simpletest_test_id}\n SET last_prefix = '%s'\n WHERE test_id = %d", $db_prefix_new, $this->testId); $db_prefix = $db_prefix_new; // Create test directory ahead of installation so fatal errors and debug // information can be logged during installation process. $directory = $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10); // file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); // Log fatal errors. ini_set('log_errors', 1); ini_set('error_log', $directory . '/error.log'); // include_once DRUPAL_ROOT . '/includes/install.inc'; include_once './includes/install.inc'; drupal_install_system(); // $this->preloadRegistry(); // // Include the default profile // variable_set('install_profile', 'default'); // $profile_details = install_profile_info('default', 'en'); // Add the specified modules to the list of modules in the default profile. // Install the modules specified by the default profile. // drupal_install_modules($profile_details['dependencies'], TRUE); drupal_install_modules(drupal_verify_profile('default', 'en')); // node_type_clear(); // Install additional modules one at a time in order to make sure that the // list of modules is updated between each module's installation. $modules = func_get_args(); foreach ($modules as $module) { // drupal_install_modules(array($module), TRUE); drupal_install_modules(array($module)); } // Because the schema is static cached, we need to flush // it between each run. If we don't, then it will contain // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); // Run default profile tasks. // $install_state = array(); // drupal_install_modules(array('default'), TRUE); $task = 'profile'; default_profile_tasks($task, ''); // Rebuild caches. // node_types_rebuild(); actions_synchronize(); _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); user_access(NULL, NULL, TRUE); // Drupal 6. // Log in with a clean $user. $this->originalUser = $user; // drupal_save_session(FALSE); // $user = user_load(1); session_save_session(FALSE); $user = user_load(array('uid' => 1)); // Restore necessary variables. variable_set('install_profile', 'default'); // variable_set('install_task', 'done'); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); variable_set('site_mail', '*****@*****.**'); // // Set up English language. // unset($GLOBALS['conf']['language_default']); // $language = language_default(); // Use the test mail class instead of the default mail handler class. // variable_set('mail_sending_system', array('default-system' => 'TestingMailSystem')); variable_set('smtp_library', drupal_get_path('module', 'simpletest') . '/simpletest.mail.inc'); // Use temporary files directory with the same prefix as the database. // $public_files_directory = $this->originalFileDirectory . '/' . $db_prefix; // $private_files_directory = $public_files_directory . '/private'; $directory = $this->originalFileDirectory . '/' . $db_prefix; // Set path variables // variable_set('file_public_path', $public_files_directory); // variable_set('file_private_path', $private_files_directory); variable_set('file_directory_path', $directory); // Create the directories // $directory = file_directory_path('public'); // file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); // file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY); file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); // drupal_set_time_limit($this->timeLimit); set_time_limit($this->timeLimit); }
/** * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ protected function setUp() { global $db_prefix, $user, $language; // $language (Drupal 6). // Store necessary current values before switching to prefixed database. $this->originalPrefix = $db_prefix; $clean_url_original = variable_get('clean_url', 0); // Must reset locale here, since schema calls t(). (Drupal 6) if (module_exists('locale')) { $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''); locale(NULL, NULL, TRUE); } // Generate temporary prefixed database to ensure that tests have a clean starting point. // $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); $db_prefix = 'simpletest' . mt_rand(1000, 1000000); // include_once DRUPAL_ROOT . '/includes/install.inc'; include_once './includes/install.inc'; drupal_install_system(); // $this->preloadRegistry(); // Add the specified modules to the list of modules in the default profile. $args = func_get_args(); // $modules = array_unique(array_merge(drupal_get_profile_modules('default', 'en'), $args)); $modules = array_unique(array_merge(drupal_verify_profile('default', 'en'), $args)); // drupal_install_modules($modules, TRUE); drupal_install_modules($modules); // Because the schema is static cached, we need to flush // it between each run. If we don't, then it will contain // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); // Run default profile tasks. $task = 'profile'; default_profile_tasks($task, ''); // Rebuild caches. actions_synchronize(); _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); user_access(NULL, NULL, TRUE); // Drupal 6. // Log in with a clean $user. $this->originalUser = $user; // drupal_save_session(FALSE); // $user = user_load(1); session_save_session(FALSE); $user = user_load(array('uid' => 1)); // Restore necessary variables. variable_set('install_profile', 'default'); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); variable_set('site_mail', '*****@*****.**'); // Use temporary files directory with the same prefix as database. $this->originalFileDirectory = file_directory_path(); variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix); $directory = file_directory_path(); // Create the files directory. file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); set_time_limit($this->timeLimit); }
/** * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. This can be * either a single array or a variable number of string arguments. */ protected function setUp() { global $user, $language, $conf; // Generate a temporary prefixed database to ensure that tests have a clean starting point. $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000); db_update('simpletest_test_id')->fields(array('last_prefix' => $this->databasePrefix))->condition('test_id', $this->testId)->execute(); // Clone the current connection and replace the current prefix. $connection_info = Database::getConnectionInfo('default'); Database::renameConnection('default', 'simpletest_original_default'); foreach ($connection_info as $target => $value) { $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix); } Database::addConnectionInfo('default', 'default', $connection_info['default']); // Store necessary current values before switching to prefixed database. $this->originalLanguage = $language; $this->originalLanguageDefault = variable_get('language_default'); $this->originalFileDirectory = file_directory_path(); $this->originalProfile = drupal_get_profile(); $clean_url_original = variable_get('clean_url', 0); // 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 // callbacks from both environments. So testing environment will try // to call handlers from original environment. $callbacks =& drupal_register_shutdown_function(); $this->originalShutdownCallbacks = $callbacks; $callbacks = array(); // Create test directory ahead of installation so fatal errors and debug // information can be logged during installation process. // Use temporary files directory with the same prefix as the database. $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10); $private_files_directory = $public_files_directory . '/private'; $temp_files_directory = $private_files_directory . '/temp'; // Create the directories file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY); file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY); $this->generatedTestFiles = FALSE; // Log fatal errors. ini_set('log_errors', 1); ini_set('error_log', $public_files_directory . '/error.log'); // Reset all statics and variables to perform tests in a clean environment. $conf = array(); drupal_static_reset(); // Set the test information for use in other parts of Drupal. $test_info =& $GLOBALS['drupal_test_info']; $test_info['test_run_id'] = $this->databasePrefix; $test_info['in_child_site'] = FALSE; include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_install_system(); $this->preloadRegistry(); // Set path variables. variable_set('file_public_path', $public_files_directory); variable_set('file_private_path', $private_files_directory); variable_set('file_temporary_path', $temp_files_directory); // Include the default profile. variable_set('install_profile', 'standard'); $profile_details = install_profile_info('standard', 'en'); // Install the modules specified by the default profile. module_enable($profile_details['dependencies'], FALSE); // Install modules needed for this test. This could have been passed in as // either a single array argument or a variable number of string arguments. // @todo Remove this compatibility layer in Drupal 8, and only accept // $modules as a single array argument. $modules = func_get_args(); if (isset($modules[0]) && is_array($modules[0])) { $modules = $modules[0]; } if ($modules) { module_enable($modules, TRUE); } // Run default profile tasks. module_enable(array('standard'), FALSE); // Rebuild caches. drupal_static_reset(); drupal_flush_all_caches(); // Register actions declared by any modules. actions_synchronize(); // Reload global $conf array and permissions. $this->refreshVariables(); $this->checkPermissions(array(), TRUE); // Reset statically cached schema for new database prefix. drupal_get_schema(NULL, TRUE); // 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', '*****@*****.**'); variable_set('date_default_timezone', date_default_timezone_get()); // Set up English language. unset($GLOBALS['conf']['language_default']); $language = language_default(); // Use the test mail class instead of the default mail handler class. variable_set('mail_system', array('default-system' => 'TestingMailSystem')); drupal_set_time_limit($this->timeLimit); }
/** * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ function setUp() { global $db_prefix, $user, $language; // $language (Drupal 6). global $install_locale; // Store necessary current values before switching to prefixed database. $this->db_prefix_original = $db_prefix; $clean_url_original = variable_get('clean_url', 0); // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix = 'simpletest' . mt_rand(1000, 1000000); include_once './includes/install.inc'; drupal_install_system(); // Add the specified modules to the list of modules in the default profile. $args = func_get_args(); // Add language and basic i18n modules $install_locale = $this->install_locale; $i18n_modules = array('locale', 'translation', 'i18n', 'i18n_test'); $modules = array_unique(array_merge(drupal_verify_profile('default', $this->install_locale), $args, $i18n_modules)); drupal_install_modules($modules); // Install locale if ($this->install_locale != 'en') { $this->addLanguage($this->install_locale, TRUE); } // Run default profile tasks. $task = 'profile'; default_profile_tasks($task, ''); // Rebuild caches. actions_synchronize(); _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); user_access(NULL, NULL, TRUE); // Drupal 6. // Log in with a clean $user. $this->originalUser = $user; // drupal_save_session(FALSE); // $user = user_load(1); session_save_session(FALSE); $user = user_load(1); // Restore necessary variables. variable_set('install_profile', 'default'); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); variable_set('site_mail', '*****@*****.**'); // Use temporary files directory with the same prefix as database. $this->originalFileDirectory = file_directory_path(); variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix); $directory = file_directory_path(); // Create the files directory. file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); drupal_set_time_limit($this->timeLimit); // Some more includes require_once 'includes/language.inc'; // Refresh theme $this->initTheme(); // Set path languages so we can retrieve pages in different languages variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH); }
/** * The Drupal installation happens in a series of steps. We begin by verifying * that the current environment meets our minimum requirements. We then go * on to verify that settings.php is properly configured. From there we * connect to the configured database and verify that it meets our minimum * requirements. Finally we can allow the user to select an installation * profile and complete the installation process. * * @param $phase * The installation phase we should proceed to. */ function install_main() { require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); // 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; } // This must go after drupal_bootstrap(), which unsets globals! global $profile, $install_locale, $conf; require_once DRUPAL_ROOT . '/modules/system/system.install'; require_once DRUPAL_ROOT . '/includes/file.inc'; // Ensure correct page headers are sent (e.g. caching) drupal_page_header(); // Set up $language, so t() caller functions will still work. drupal_init_language(); // Load module basics (needed for hook invokes). include_once DRUPAL_ROOT . '/includes/module.inc'; $module_list['system']['filename'] = 'modules/system/system.module'; $module_list['filter']['filename'] = 'modules/filter/filter.module'; module_list(TRUE, FALSE, FALSE, $module_list); drupal_load('module', 'system'); drupal_load('module', 'filter'); // Load the cache infrastructure using a "fake" cache implementation that // does not attempt to write to the database. We need this during the initial // part of the installer because the database is not available yet. We // continue to use it even when the database does become available, in order // to preserve consistency between interactive and command-line installations // (the latter complete in one page request and therefore are forced to // continue using the cache implementation they started with) and also // because any data put in the cache during the installer is inherently // suspect, due to the fact that Drupal is not fully set up yet. require_once DRUPAL_ROOT . '/includes/cache-install.inc'; $conf['cache_inc'] = './includes/cache-install.inc'; // Install profile chosen, set the global immediately. // This needs to be done before the theme cache gets // initialized in drupal_maintenance_theme(). if (!empty($_GET['profile'])) { $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']); } // Set up theme system for the maintenance page. drupal_maintenance_theme(); // Check existing settings.php. $verify = install_verify_settings(); if ($verify) { // Establish a connection to the database. require_once DRUPAL_ROOT . '/includes/database.inc'; db_set_active(); // Check if Drupal is installed. $task = install_verify_drupal(); if ($task == 'done') { install_already_done_error(); } } else { $task = NULL; } // No profile was passed in GET, ask the user. if (empty($_GET['profile'])) { if ($profile = install_select_profile()) { install_goto("install.php?profile={$profile}"); } else { install_no_profile_error(); } } // Load the profile. require_once DRUPAL_ROOT . "/profiles/{$profile}/{$profile}.profile"; // Locale selection if (!empty($_GET['locale'])) { $install_locale = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $_GET['locale']); } elseif (($install_locale = install_select_locale($profile)) !== FALSE) { install_goto("install.php?profile={$profile}&locale={$install_locale}"); } // Tasks come after the database is set up if (!$task) { global $db_url; if (!$verify && !empty($db_url)) { // Do not install over a configured settings.php. install_already_done_error(); } // Check the installation requirements for Drupal and this profile. install_check_requirements($profile, $verify); // Verify existence of all required modules. $modules = drupal_verify_profile($profile, $install_locale); // If any error messages are set now, it means a requirement problem. $messages = drupal_set_message(); if (!empty($messages['error'])) { install_task_list('requirements'); drupal_set_title(st('Requirements problem')); print theme('install_page', ''); exit; } // Change the settings.php information if verification failed earlier. // Note: will trigger a redirect if database credentials change. if (!$verify) { install_change_settings($profile, $install_locale); } // The default lock implementation uses a database table, // so we cannot use it for install, but we still need // the API functions available. require_once './includes/lock-install.inc'; $conf['lock_inc'] = './includes/lock-install.inc'; lock_init(); // Install system.module. drupal_install_system(); // Ensure that all of Drupal's standard directories have appropriate // .htaccess files. These directories will have already been created by // this point in the installer, since Drupal creates them during the // install_check_requirements() task. Note that we cannot create them any // earlier than this, since the code below relies on system.module in order // to work. file_create_htaccess(file_directory_path()); file_create_htaccess(file_directory_temp()); // Save the list of other modules to install for the 'profile-install' // task. variable_set() can be used now that system.module is installed // and drupal is bootstrapped. variable_set('install_profile_modules', array_diff($modules, array('system'))); } // The database is set up, turn to further tasks. install_tasks($profile, $task); }