Created
December 5, 2009 16:43
-
-
Save smerrill/249754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Test case for Drupal tests using a given install profile. | |
* | |
* Based on work that is copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218) | |
*/ | |
class ProvisionWebTestCase extends DrupalWebTestCase { | |
protected function getProfileName() { | |
return 'provision'; | |
} | |
/** | |
* 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). | |
$profile_name = $this->getProfileName(); | |
// Store necessary current values before switching to prefixed database. | |
$this->originalPrefix = $db_prefix; | |
$this->originalFileDirectory = file_directory_path(); | |
$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 = '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(); | |
$modules = array_unique(array_merge(drupal_verify_profile($profile_name, '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'; | |
$func = "{$profile_name}_profile_tasks"; | |
$func($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; | |
session_save_session(FALSE); | |
$user = user_load(array('uid' => 1)); | |
// Restore necessary variables. | |
variable_set('install_profile', $profile_name); | |
variable_set('install_task', 'profile-finished'); | |
variable_set('clean_url', $clean_url_original); | |
variable_set('site_mail', '[email protected]'); | |
// 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment