You are here

protected function DrupalWebTestCase::preloadRegistry in Drupal 7

Preload the registry from the testing site.

This method is called by DrupalWebTestCase::setUp(), and preloads the registry from the testing site to cut down on the time it takes to set up a clean environment for the current test run.

1 call to DrupalWebTestCase::preloadRegistry()
DrupalWebTestCase::setUp in modules/simpletest/drupal_web_test_case.php
Sets up a Drupal site for running functional and integration tests.

File

modules/simpletest/drupal_web_test_case.php, line 1804

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function preloadRegistry() {

  // Use two separate queries, each with their own connections: copy the
  // {registry} and {registry_file} tables over from the parent installation
  // to the child installation.
  $original_connection = Database::getConnection('default', 'simpletest_original_default');
  $test_connection = Database::getConnection();
  foreach (array(
    'registry',
    'registry_file',
  ) as $table) {

    // Find the records from the parent database.
    $source_query = $original_connection
      ->select($table, array(), array(
      'fetch' => PDO::FETCH_ASSOC,
    ))
      ->fields($table);
    $dest_query = $test_connection
      ->insert($table);
    $first = TRUE;
    foreach ($source_query
      ->execute() as $row) {
      if ($first) {
        $dest_query
          ->fields(array_keys($row));
        $first = FALSE;
      }

      // Insert the records into the child database.
      $dest_query
        ->values($row);
    }
    $dest_query
      ->execute();
  }
}