Chris@0: siteDirectory = $test_db->getTestSitePath(); Chris@0: $this->databasePrefix = $test_db->getDatabasePrefix(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Changes the database connection to the prefixed one. Chris@0: */ Chris@0: protected function changeDatabasePrefix() { Chris@0: if (empty($this->databasePrefix)) { Chris@0: $this->prepareDatabasePrefix(); Chris@0: } Chris@0: Chris@0: // If the test is run with argument dburl then use it. Chris@0: $db_url = getenv('SIMPLETEST_DB'); Chris@0: if (!empty($db_url)) { Chris@17: // Ensure no existing database gets in the way. If a default database Chris@17: // exists already it must be removed. Chris@17: Database::removeConnection('default'); Chris@0: $database = Database::convertDbUrlToConnectionInfo($db_url, isset($this->root) ? $this->root : DRUPAL_ROOT); Chris@0: Database::addConnectionInfo('default', 'default', $database); Chris@0: } Chris@0: Chris@0: // Clone the current connection and replace the current prefix. Chris@0: $connection_info = Database::getConnectionInfo('default'); Chris@0: if (is_null($connection_info)) { Chris@0: throw new \InvalidArgumentException('There is no database connection so no tests can be run. You must provide a SIMPLETEST_DB environment variable to run PHPUnit based functional tests outside of run-tests.sh.'); Chris@0: } Chris@0: else { Chris@0: Database::renameConnection('default', 'simpletest_original_default'); Chris@0: foreach ($connection_info as $target => $value) { Chris@0: // Replace the full table prefix definition to ensure that no table Chris@0: // prefixes of the test runner leak into the test. Chris@0: $connection_info[$target]['prefix'] = [ Chris@0: 'default' => $value['prefix']['default'] . $this->databasePrefix, Chris@0: ]; Chris@0: } Chris@0: Database::addConnectionInfo('default', 'default', $connection_info['default']); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the config schema exclusions for this test. Chris@0: * Chris@0: * @return string[] Chris@0: * An array of config object names that are excluded from schema checking. Chris@0: */ Chris@0: protected function getConfigSchemaExclusions() { Chris@0: $class = get_class($this); Chris@0: $exceptions = []; Chris@0: while ($class) { Chris@0: if (property_exists($class, 'configSchemaCheckerExclusions')) { Chris@0: $exceptions = array_merge($exceptions, $class::$configSchemaCheckerExclusions); Chris@0: } Chris@0: $class = get_parent_class($class); Chris@0: } Chris@0: // Filter out any duplicates. Chris@0: return array_unique($exceptions); Chris@0: } Chris@0: Chris@0: }