CiviCrmTestBase.php in Webform CiviCRM Integration 8.5
File
tests/src/FunctionalJavascript/CiviCrmTestBase.php
View source
<?php
namespace Drupal\Tests\webform_civicrm\FunctionalJavascript;
use Drupal\Core\Database\Database;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
abstract class CiviCrmTestBase extends WebDriverTestBase {
protected $defaultTheme = 'classy';
protected static $modules = [
'block',
'civicrm',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('local_actions_block');
}
protected function cleanupEnvironment() {
parent::cleanupEnvironment();
$civicrm_test_conn = Database::getConnection('default', 'civicrm_test');
$civicrm_test_conn
->query('SET FOREIGN_KEY_CHECKS = 0;')
->execute();
$civicrm_schema = $civicrm_test_conn
->schema();
$tables = $civicrm_schema
->findTables('%');
foreach ($tables as $table) {
if ($civicrm_schema
->dropTable($table)) {
unset($tables[$table]);
}
}
$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();
}
protected function changeDatabasePrefix() {
parent::changeDatabasePrefix();
$connection_info = Database::getConnectionInfo('default');
$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);
$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.');
}
}
protected function prepareSettings() {
parent::prepareSettings();
$filename = $this->siteDirectory . '/settings.php';
chmod($filename, 0666);
$constants = <<<CONSTANTS
if (!defined('CIVICRM_CONTAINER_CACHE')) {
define('CIVICRM_CONTAINER_CACHE', 'never');
}
if (!defined('CIVICRM_TEST')) {
define('CIVICRM_TEST', 'never');
}
CONSTANTS;
file_put_contents($filename, $constants, FILE_APPEND);
}
}