protected function DrupalUnitTestCase::setUp in SimpleTest 6.2
Same name and namespace in other branches
- 7.2 drupal_web_test_case.php \DrupalUnitTestCase::setUp()
- 7 drupal_web_test_case.php \DrupalUnitTestCase::setUp()
Sets up unit test environment.
Unlike DrupalWebTestCase::setUp(), DrupalUnitTestCase::setUp() does not install modules because tests are performed without accessing the database. Any required files must be explicitly included by the child class setUp() method.
File
- ./
drupal_web_test_case.php, line 664
Class
- DrupalUnitTestCase
- Test case for Drupal unit tests.
Code
protected function setUp() {
global $conf;
// Store necessary current values before switching to the test environment.
$this->originalPrefix = $GLOBALS['db_prefix'];
$this->originalFileDirectory = variable_get('file_directory_path', conf_path() . '/files');
// Generate temporary prefixed database to ensure that tests have a clean starting point.
$this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
// Create test directory.
$public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10);
file_check_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$conf['file_directory_path'] = $public_files_directory;
// Clone the current connection and replace the current prefix.
$GLOBALS['db_prefix'] = is_array($GLOBALS['db_prefix']) ? $GLOBALS['db_prefix']['default'] : $GLOBALS['db_prefix'] . $this->databasePrefix;
// If locale is enabled then t() will try to access the database and
// subsequently will fail as the database is not accessible.
$module_list = module_list();
if (isset($module_list['locale'])) {
$this->originalModuleList = $module_list;
unset($module_list['locale']);
module_list(TRUE, FALSE, FALSE, $module_list);
}
}