You are here

function KernelTestBaseTest::testInstallSchema in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/Tests/KernelTestBaseTest.php \Drupal\simpletest\Tests\KernelTestBaseTest::testInstallSchema()

Tests expected behavior of installSchema().

File

core/modules/simpletest/src/Tests/KernelTestBaseTest.php, line 156
Contains \Drupal\simpletest\Tests\KernelTestBaseTest.

Class

KernelTestBaseTest
Tests KernelTestBase functionality.

Namespace

Drupal\simpletest\Tests

Code

function testInstallSchema() {
  $module = 'entity_test';
  $table = 'entity_test_example';

  // Verify that we can install a table from the module schema.
  $this
    ->installSchema($module, $table);
  $this
    ->assertTrue(db_table_exists($table), "'{$table}' database table found.");

  // Verify that the schema is known to Schema API.
  $schema = drupal_get_module_schema($module, $table);
  $this
    ->assertTrue($schema, "'{$table}' table schema found.");

  // Verify that a unknown table from an enabled module throws an error.
  $table = 'unknown_entity_test_table';
  try {
    $this
      ->installSchema($module, $table);
    $this
      ->fail('Exception for non-retrievable schema found.');
  } catch (\Exception $e) {
    $this
      ->pass('Exception for non-retrievable schema found.');
  }
  $this
    ->assertFalse(db_table_exists($table), "'{$table}' database table not found.");
  $schema = drupal_get_module_schema($module, $table);
  $this
    ->assertFalse($schema, "'{$table}' table schema not found.");

  // Verify that a table from a unknown module cannot be installed.
  $module = 'database_test';
  $table = 'test';
  try {
    $this
      ->installSchema($module, $table);
    $this
      ->fail('Exception for non-retrievable schema found.');
  } catch (\Exception $e) {
    $this
      ->pass('Exception for non-retrievable schema found.');
  }
  $this
    ->assertFalse(db_table_exists($table), "'{$table}' database table not found.");
  $schema = drupal_get_module_schema($module, $table);
  $this
    ->assertTrue($schema, "'{$table}' table schema found.");

  // Verify that the same table can be installed after enabling the module.
  $this
    ->enableModules(array(
    $module,
  ));
  $this
    ->installSchema($module, $table);
  $this
    ->assertTrue(db_table_exists($table), "'{$table}' database table found.");
  $schema = drupal_get_module_schema($module, $table);
  $this
    ->assertTrue($schema, "'{$table}' table schema found.");
}