You are here

public function ModuleTestBase::assertModuleTablesExist in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleTablesExist()
  2. 9 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleTablesExist()

Assert that all tables defined in a module's hook_schema() exist.

Parameters

$module: The name of the module.

1 call to ModuleTestBase::assertModuleTablesExist()
InstallUninstallTest::assertModuleSuccessfullyInstalled in core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php
Asserts that a module was successfully installed.

File

core/modules/system/tests/src/Functional/Module/ModuleTestBase.php, line 43

Class

ModuleTestBase
Helper class for module test cases.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function assertModuleTablesExist($module) {
  $tables = array_keys(SchemaInspector::getTablesSpecification(\Drupal::moduleHandler(), $module));
  $tables_exist = TRUE;
  $schema = Database::getConnection()
    ->schema();
  foreach ($tables as $table) {
    if (!$schema
      ->tableExists($table)) {
      $tables_exist = FALSE;
    }
  }
  $this
    ->assertTrue($tables_exist, new FormattableMarkup('All database tables defined by the @module module exist.', [
    '@module' => $module,
  ]));
}