You are here

protected function DeployWebTestCase::switchSite in Deploy - Content Staging 7.3

Same name and namespace in other branches
  1. 7.2 deploy.test \DeployWebTestCase::switchSite()

Switch to a specific site.

2 calls to DeployWebTestCase::switchSite()
DeployWebTestCase::runScenario in ./deploy.test
This method runs a deployment scenario where we have one production site (the endpoint) and a staging site (the origin).
DeployWebTestCase::setUp in ./deploy.test
Set up all sites.

File

./deploy.test, line 117
Deployment tests.

Class

DeployWebTestCase
Helper class.

Code

protected function switchSite($from, $to) {

  // This is used to test the switch.
  $old_site_hash = variable_get('deploy_site_hash', '');

  // Switch database connection. This is where the magic happens.
  Database::renameConnection('default', $from);
  Database::renameConnection($to, 'default');

  // Reset static caches, so sites doesn't share them.
  drupal_static_reset();

  // Since variables ($conf) lives in the global namespace, we need to
  // reinitalize them to not make sites share variables.
  cache_clear_all('*', 'cache_bootstrap');
  $GLOBALS['conf'] = variable_initialize();

  // No need to restore anything if we are switching to the original site.
  if ($to != 'simpletest_original_default') {
    $this
      ->restoreState($to);

    // Test the switch.
    $new_site_hash = variable_get('deploy_site_hash', '');
    $this
      ->assertNotEqual($old_site_hash, $new_site_hash, t('Switch to site %key was successful.', array(
      '%key' => $to,
    )));
  }
}