function ModuleTestBase::assertModuleTablesExist

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleTablesExist()
  2. 8.9.x core/modules/system/src/Tests/Module/ModuleTestBase.php \Drupal\system\Tests\Module\ModuleTestBase::assertModuleTablesExist()
  3. 8.9.x core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleTablesExist()
  4. 11.x 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()
ConfigImportAllTest::testInstallUninstall in core/modules/config/tests/src/Functional/ConfigImportAllTest.php
Tests that a fixed set of modules can be installed and uninstalled.

File

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

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, "All database tables defined by the {$module} module exist.");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.