You are here

protected function MigrateUpgradeTestBase::createMigrationConnection in Drupal 10

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. 9 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

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\Tests\BrowserTestBase::cleanupEnvironment() 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'];

    // Test databases use fixed length prefixes. Create a new prefix for the
    // source database. Adding to the end of the prefix ensures that
    // \Drupal\Tests\BrowserTestBase::cleanupEnvironment() will remove the
    // additional tables.
    $connection_info['prefix'] = $prefix . '0';
  }
  Database::addConnectionInfo('migrate_drupal_ui', 'default', $connection_info);
}