You are here

protected function DrupalWebTestCase::setUp in SimpleTest 7

Same name and namespace in other branches
  1. 6.2 drupal_web_test_case.php \DrupalWebTestCase::setUp()
  2. 7.2 drupal_web_test_case.php \DrupalWebTestCase::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.

Parameters

...: List of modules to enable for the duration of the test.

55 calls to DrupalWebTestCase::setUp()
ActionLoopTestCase::setUp in tests/actions.test
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.…
AJAXTestCase::setUp in tests/ajax.test
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.…
BatchAPIPercentagesTestCase::setUp in tests/batch.test
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.…
BootstrapIPAddressTestCase::setUp in tests/bootstrap.test
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.…
BootstrapPageCacheTestCase::setUp in tests/bootstrap.test
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.…

... See full list

55 methods override DrupalWebTestCase::setUp()
ActionLoopTestCase::setUp in tests/actions.test
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.…
AJAXTestCase::setUp in tests/ajax.test
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.…
BatchAPIPercentagesTestCase::setUp in tests/batch.test
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.…
BootstrapIPAddressTestCase::setUp in tests/bootstrap.test
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.…
BootstrapPageCacheTestCase::setUp in tests/bootstrap.test
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.…

... See full list

File

./drupal_web_test_case.php, line 1027

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function setUp(array $modules = array()) {
  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.
  $directory = $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10);
  file_prepare_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';
  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_static_reset('_node_types_build');

  // Install additional modules one at a time in order to make sure that the
  // list of modules is updated between each module's installation.
  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.
  $install_state = array();
  drupal_install_modules(array(
    'default',
  ), 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_profile', 'default');
  variable_set('install_task', 'done');
  variable_set('clean_url', $clean_url_original);
  variable_set('site_mail', 'simpletest@example.com');

  // 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',
  ));

  // 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';

  // Set path variables
  variable_set('file_public_path', $public_files_directory);
  variable_set('file_private_path', $private_files_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);
  drupal_set_time_limit($this->timeLimit);
}