protected function DrupalUnitTestBase::installSchema

Installs a specific table from a module schema definition.

Use this to install a particular table from System module.

Parameters

string $module: The name of the module that defines the table's schema.

string $table: The name of the table to install.

2 calls to DrupalUnitTestBase::installSchema()
DrupalUnitTestBaseTest::testEnableModulesInstall in drupal/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
Tests expected installation behavior of enableModules().
DrupalUnitTestBaseTest::testInstallSchema in drupal/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
Tests expected behavior of installSchema().

File

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

Class

DrupalUnitTestBase
Base test case class for Drupal unit tests.

Namespace

Drupal\simpletest

Code

protected function installSchema($module, $table) {

  // 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 (!module_exists($module)) {
    throw new \RuntimeException(format_string("'@module' module is not enabled.", array(
      '@module' => $module,
    )));
  }
  $schema = drupal_get_schema_unprocessed($module, $table);
  if (empty($schema)) {
    throw new \RuntimeException(format_string("Unable to retrieve '@module' module schema for '@table' table.", array(
      '@module' => $module,
      '@table' => $table,
    )));
  }
  Database::getConnection()
    ->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);
}