You are here

protected function CiviCrmTestBase::changeDatabasePrefix in Webform CiviCRM Integration 8.5

Changes the database connection to the prefixed one.

Overrides TestSetupTrait::changeDatabasePrefix

File

tests/src/FunctionalJavascript/CiviCrmTestBase.php, line 60

Class

CiviCrmTestBase

Namespace

Drupal\Tests\webform_civicrm\FunctionalJavascript

Code

protected function changeDatabasePrefix() {
  parent::changeDatabasePrefix();
  $connection_info = Database::getConnectionInfo('default');

  // CiviCRM does not leverage table prefixes, so we unset it. This way any
  // `civicrm_` tables are more easily cleaned up at the end of the test.
  $civicrm_connection_info = $connection_info['default'];
  unset($civicrm_connection_info['prefix']);
  Database::addConnectionInfo('civicrm_test', 'default', $civicrm_connection_info);
  Database::addConnectionInfo('civicrm', 'default', $civicrm_connection_info);

  // Assert that there are no `civicrm_` tables in the test database.
  $connection = Database::getConnection('default', 'civicrm_test');
  $schema = $connection
    ->schema();
  $tables = $schema
    ->findTables('civicrm_%');
  if (count($tables) > 0) {
    throw new \RuntimeException('The provided database connection in SIMPLETEST_DB contains CiviCRM tables, use a different database.');
  }
}