protected function KernelTestBase::installSchema in Drupal 8
Same name in this branch
- 8 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installSchema()
- 8 core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::installSchema()
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installSchema()
- 10 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installSchema()
Installs database tables from a module schema definition.
Parameters
string $module: The name of the module that defines the table's schema.
string|array $tables: The name or an array of the names of the tables to install.
Throws
\LogicException If $module is not enabled or the table schema cannot be found.
245 calls to KernelTestBase::installSchema()
- AccessPermissionTest::setUp in core/
modules/ user/ tests/ src/ Kernel/ Views/ AccessPermissionTest.php - AccessTest::setUp in core/
modules/ file/ tests/ src/ Kernel/ AccessTest.php - ActionTest::setUp in core/
modules/ system/ tests/ src/ Kernel/ Action/ ActionTest.php - AnonymousPrivateTempStoreTest::setUp in core/
tests/ Drupal/ KernelTests/ Core/ TempStore/ AnonymousPrivateTempStoreTest.php - ArgumentDefaultTest::testPluginArgumentDefaultCurrentUser in core/
modules/ user/ tests/ src/ Kernel/ Views/ ArgumentDefaultTest.php - Tests the current user with argument default.
File
- core/
tests/ Drupal/ KernelTests/ KernelTestBase.php, line 709
Class
- KernelTestBase
- Base class for functional integration tests.
Namespace
Drupal\KernelTestsCode
protected function installSchema($module, $tables) {
// drupal_get_module_schema() is technically able to install a schema
// of a non-enabled module, but its ability to load the module's .install
// file depends on many other factors. To prevent differences in test
// behavior and non-reproducible test failures, we only allow the schema of
// explicitly loaded/enabled modules to be installed.
if (!$this->container
->get('module_handler')
->moduleExists($module)) {
throw new \LogicException("{$module} module is not enabled.");
}
$tables = (array) $tables;
foreach ($tables as $table) {
$schema = drupal_get_module_schema($module, $table);
if (empty($schema)) {
// BC layer to avoid some contrib tests to fail.
if ($module == 'system') {
@trigger_error('Special handling of system module schemas in \\Drupal\\KernelTests\\KernelTestBase::installSchema has been deprecated in Drupal 8.7.x, remove any calls to this method that use invalid schema names. See https://www.drupal.org/node/3003360.', E_USER_DEPRECATED);
continue;
}
throw new \LogicException("{$module} module does not define a schema for table '{$table}'.");
}
$this->container
->get('database')
->schema()
->createTable($table, $schema);
}
}