You are here

protected function DrupalWebTestCase::preloadRegistry in SimpleTest 7.2

Same name and namespace in other branches
  1. 7 drupal_web_test_case.php \DrupalWebTestCase::preloadRegistry()

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::setUpInstall in ./drupal_web_test_case.php
Perform Drupal installation.

File

./drupal_web_test_case.php, line 1407
Provides DrupalTestCase, DrupalUnitTestCase, and DrupalWebTestCase classes.

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