protected function UpgradePathTestBase::setUp

Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.

Overrides WebTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

21 calls to UpgradePathTestBase::setUp()
ActionUpgradePathTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/ActionUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
BareMinimalUpgradePathTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
BareStandardUpgradePathTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareStandardUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
BlockUpgradePathTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
ContactUpgradePathTest::setUp in drupal/core/modules/contact/lib/Drupal/contact/Tests/ContactUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.

... See full list

21 methods override UpgradePathTestBase::setUp()
ActionUpgradePathTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/ActionUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
BareMinimalUpgradePathTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
BareStandardUpgradePathTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareStandardUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
BlockUpgradePathTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
ContactUpgradePathTest::setUp in drupal/core/modules/contact/lib/Drupal/contact/Tests/ContactUpgradePathTest.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.

... See full list

File

drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php, line 90
Definition of Drupal\system\Tests\Upgrade\UpgradePathTestBase.

Class

UpgradePathTestBase
Perform end-to-end tests of the upgrade path.

Namespace

Drupal\system\Tests\Upgrade

Code

protected function setUp() {
  global $user, $conf;

  // Load the Update API.
  require_once DRUPAL_ROOT . '/core/includes/update.inc';

  // Reset flags.
  $this->upgradedSite = FALSE;
  $this->upgradeErrors = array();

  // Create the database prefix for this test.
  $this
    ->prepareDatabasePrefix();

  // Prepare the environment for running tests.
  $this
    ->prepareEnvironment();
  if (!$this->setupEnvironment) {
    return FALSE;
  }

  // Reset all statics and variables to perform tests in a clean environment.
  $conf = array();
  drupal_static_reset();

  // Build a minimal, partially mocked environment for unit tests.
  $this
    ->containerBuild(drupal_container());

  // Make sure it survives kernel rebuilds.
  $conf['container_bundles'][] = 'Drupal\\simpletest\\TestBundle';

  // Change the database prefix.
  // All static variables need to be reset before the database prefix is
  // changed, since Drupal\Core\Utility\CacheArray implementations attempt to
  // write back to persistent caches when they are destructed.
  $this
    ->changeDatabasePrefix();
  if (!$this->setupDatabasePrefix) {
    return FALSE;
  }

  // Load the database from the portable PHP dump.
  // The files may be gzipped.
  foreach ($this->databaseDumpFiles as $file) {
    if (substr($file, -3) == '.gz') {
      $file = "compress.zlib://{$file}";
    }
    require $file;
  }

  // Set path variables.
  $this
    ->variable_set('file_public_path', $this->public_files_directory);
  $this
    ->variable_set('file_private_path', $this->private_files_directory);
  $this
    ->variable_set('file_temporary_path', $this->temp_files_directory);
  $this
    ->pass('Finished loading the dump.');

  // Ensure that the session is not written to the new environment and replace
  // the global $user session with uid 1 from the new test site.
  drupal_save_session(FALSE);

  // Login as uid 1.
  $user = db_query('SELECT * FROM {users} WHERE uid = :uid', array(
    ':uid' => 1,
  ))
    ->fetchObject();

  // Load roles for the user object.
  $roles = array(
    DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
  );
  $result = db_query('SELECT rid, uid FROM {users_roles} WHERE uid = :uid', array(
    ':uid' => 1,
  ));
  foreach ($result as $record) {
    $roles[$record->rid] = $record->rid;
  }
  $user->roles = $roles;

  // Generate and set a D8-compatible session cookie.
  $this
    ->prepareD8Session();

  // Restore necessary variables.
  $this
    ->variable_set('site_mail', 'simpletest@example.com');
  drupal_set_time_limit($this->timeLimit);
  $this->setup = TRUE;
}