You are here

protected function CiviCrmTestBase::cleanupEnvironment in Webform CiviCRM Integration 8.5

Clean up the Simpletest environment.

Overrides BrowserTestBase::cleanupEnvironment

File

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

Class

CiviCrmTestBase

Namespace

Drupal\Tests\webform_civicrm\FunctionalJavascript

Code

protected function cleanupEnvironment() {
  parent::cleanupEnvironment();
  $civicrm_test_conn = Database::getConnection('default', 'civicrm_test');

  // Disable foreign key checks so that tables can be dropped.
  $civicrm_test_conn
    ->query('SET FOREIGN_KEY_CHECKS = 0;')
    ->execute();
  $civicrm_schema = $civicrm_test_conn
    ->schema();
  $tables = $civicrm_schema
    ->findTables('%');

  // Comment out if you want to view the tables/contents before deleting them
  // throw new \Exception(var_export($tables, TRUE));
  foreach ($tables as $table) {
    if ($civicrm_schema
      ->dropTable($table)) {
      unset($tables[$table]);
    }
  }

  // Drop case views if present. These are removed in the civi version 5.37.alpha1 https://github.com/civicrm/civicrm-core/pull/19642
  // so these stmts wont be needed after few days when our test setup is configured to run on civi > 5.37.alpha1.
  $civicrm_test_conn
    ->query('DROP VIEW IF EXISTS civicrm_view_case_activity_recent;')
    ->execute();
  $civicrm_test_conn
    ->query('DROP VIEW IF EXISTS civicrm_view_case_activity_upcoming;')
    ->execute();
  $civicrm_test_conn
    ->query('SET FOREIGN_KEY_CHECKS = 1;')
    ->execute();
}