You are here

protected function KernelTestBase::installSchema in Zircon Profile 8

Same name in this branch
  1. 8 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installSchema()
  2. 8 core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::installSchema()
Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::installSchema()

Installs a specific table 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

\RuntimeException Thrown when $module is not enabled or when the table schema cannot be found in the module specified.

144 calls to KernelTestBase::installSchema()
ActionUnitTest::setUp in core/modules/system/src/Tests/Action/ActionUnitTest.php
Performs setup tasks before each individual test method is run.
AttachedAssetsTest::setUp in core/modules/system/src/Tests/Common/AttachedAssetsTest.php
Performs setup tasks before each individual test method is run.
BlockConfigSchemaTest::setUp in core/modules/block/src/Tests/BlockConfigSchemaTest.php
Performs setup tasks before each individual test method is run.
BookUninstallTest::setUp in core/modules/book/src/Tests/BookUninstallTest.php
Performs setup tasks before each individual test method is run.
BreakpointDiscoveryTest::setUp in core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php
Performs setup tasks before each individual test method is run.

... See full list

File

core/modules/simpletest/src/KernelTestBase.php, line 423
Contains \Drupal\simpletest\KernelTestBase.

Class

KernelTestBase
Base class for integration tests.

Namespace

Drupal\simpletest

Code

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 \RuntimeException("'{$module}' module is not enabled");
  }
  $tables = (array) $tables;
  foreach ($tables as $table) {
    $schema = drupal_get_module_schema($module, $table);
    if (empty($schema)) {
      throw new \RuntimeException("Unknown '{$table}' table schema in '{$module}' module.");
    }
    $this->container
      ->get('database')
      ->schema()
      ->createTable($table, $schema);
  }
  $this
    ->pass(format_string('Installed %module tables: %tables.', array(
    '%tables' => '{' . implode('}, {', $tables) . '}',
    '%module' => $module,
  )));
}