You are here

protected function DrupalRemoteTestCase::setUp in SimpleTest 7.2

Determine when to run against remote environment.

Overrides DrupalWebTestCase::setUp

1 call to DrupalRemoteTestCase::setUp()
DrupalRemoteTestCase::setUrl in ./drupal_web_test_case.php
Set the remote URL base.

File

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

Class

DrupalRemoteTestCase
Base class used for writing atomic remote tests.

Code

protected function setUp() {

  //     // BEGIN: Excerpt from DrupalUnitTestCase.
  //     global $conf;
  //
  // Set to that verbose mode works properly.
  $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');

  //
  //     spl_autoload_register('db_autoload');
  //
  //     // Reset all statics so that test is performed with a clean environment.
  //     drupal_static_reset();
  //
  //     // Generate temporary prefixed database to ensure that tests have a clean starting point.
  //     $this->databasePrefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
  //     $conf['file_public_path'] = $this->originalFileDirectory . '/' . $this->databasePrefix;
  //
  // Clone the current connection and replace the current prefix.
  $connection_info = Database::getConnectionInfo('default');
  Database::renameConnection('default', 'simpletest_original_default');
  foreach ($connection_info as $target => $value) {
    $connection_info[$target]['prefix'] = array(
      'default' => $value['prefix']['default'] . $this->databasePrefix,
    );
  }
  Database::addConnectionInfo('default', 'default', $connection_info['default']);

  //
  //     // Set user agent to be consistent with web test case.
  //     $_SERVER['HTTP_USER_AGENT'] = $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);
  //     }
  //     // END: Excerpt from DrupalUnitTestCase.
  if (!$this->remoteUrl && !($this->remoteUrl = variable_get('simpletest_remote_url', FALSE))) {
    $this->remoteUrl = url('', array(
      'absolute' => TRUE,
    ));
  }

  // Point the internal browser to the staging site.
  foreach (self::$URL_VARIABLES as $variable) {
    $this->originalUrls[$variable] = $GLOBALS[$variable];
    $GLOBALS[$variable] = $this->remoteUrl;
  }
  $GLOBALS['base_secure_url'] = str_replace('http://', 'https://', $GLOBALS['base_secure_url']);

  // Generate unique remote prefix.
  self::$REMOTE_PREFIX = 'test' . mt_rand(100, 100000);

  // Set the time-limit for the test case.
  drupal_set_time_limit($this->timeLimit);
}