You are here

function DrupalUnitTestCase::setUp in SimpleTest 7

Same name and namespace in other branches
  1. 6.2 drupal_web_test_case.php \DrupalUnitTestCase::setUp()
  2. 7.2 drupal_web_test_case.php \DrupalUnitTestCase::setUp()
1 call to DrupalUnitTestCase::setUp()
CommonSizeTestCase::setUp in tests/common.test
1 method overrides DrupalUnitTestCase::setUp()
CommonSizeTestCase::setUp in tests/common.test

File

./drupal_web_test_case.php, line 534

Class

DrupalUnitTestCase
Test case for Drupal unit tests.

Code

function setUp(array $modules = array()) {
  global $db_prefix, $conf;

  // Store necessary current values before switching to prefixed database.
  $this->originalPrefix = $db_prefix;
  $this->originalFileDirectory = file_directory_path();

  // Generate temporary prefixed database to ensure that tests have a clean starting point.
  $db_prefix = Database::getConnection()
    ->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
  $conf['file_public_path'] = $this->originalFileDirectory . '/' . $db_prefix;

  // 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);
  }
}