You are here

protected function MigrateUpgradeTestBase::createMigrationConnection in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php \Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeTestBase::createMigrationConnection()
  2. 10 core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php \Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeTestBase::createMigrationConnection()

Changes the database connection to the prefixed one.

@todo Remove when we don't use global. https://www.drupal.org/node/2552791

1 call to MigrateUpgradeTestBase::createMigrationConnection()
MigrateUpgradeTestBase::setUp in core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php

File

core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php, line 98

Class

MigrateUpgradeTestBase
Provides a base class for testing migration upgrades in the UI.

Namespace

Drupal\Tests\migrate_drupal_ui\Functional

Code

protected function createMigrationConnection() {
  $connection_info = Database::getConnectionInfo('default')['default'];
  if ($connection_info['driver'] === 'sqlite') {

    // Create database file in the test site's public file directory so that
    // \Drupal\simpletest\TestBase::restoreEnvironment() will delete this once
    // the test is complete.
    $file = $this->publicFilesDirectory . '/' . $this->testId . '-migrate.db.sqlite';
    touch($file);
    $connection_info['database'] = $file;
    $connection_info['prefix'] = '';
  }
  else {
    $prefix = $connection_info['prefix'];

    // Simpletest uses fixed length prefixes. Create a new prefix for the
    // source database. Adding to the end of the prefix ensures that
    // \Drupal\simpletest\TestBase::restoreEnvironment() will remove the
    // additional tables.
    $connection_info['prefix'] = $prefix . '0';
  }
  Database::addConnectionInfo('migrate_drupal_ui', 'default', $connection_info);
}