protected function DrupalUnitTestBase::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.

74 calls to DrupalUnitTestBase::installSchema()
ActionUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Action/ActionUnitTest.php
Sets up Drupal unit test environment.
BlockInterfaceTest::setUp in drupal/core/modules/block/lib/Drupal/block/Tests/BlockInterfaceTest.php
Sets up Drupal unit test environment.
CKEditorPluginManagerTest::setUp in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php
Sets up Drupal unit test environment.
CKEditorTest::setUp in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
Sets up Drupal unit test environment.
ConfigImporterTest::setUp in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php
Sets up Drupal unit test environment.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php, line 217
Contains Drupal\simpletest\DrupalUnitTestBase.

Class

DrupalUnitTestBase
Base test case class for Drupal unit tests.

Namespace

Drupal\simpletest

Code

protected function installSchema($module, $tables) {

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

  // We need to refresh the schema cache, as any call to drupal_get_schema()
  // would not know of/return the schema otherwise.
  // @todo Refactor Schema API to make this obsolete.
  drupal_get_schema(NULL, TRUE);
  $this
    ->pass(format_string('Installed %module tables: %tables.', array(
    '%tables' => '{' . implode('}, {', $tables) . '}',
    '%module' => $module,
  )));
}