You are here

public function ModuleTestBase::assertTableCount in Drupal 8

Same name in this branch
  1. 8 core/modules/system/src/Tests/Module/ModuleTestBase.php \Drupal\system\Tests\Module\ModuleTestBase::assertTableCount()
  2. 8 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertTableCount()

Assert there are tables that begin with the specified base table name.

Parameters

$base_table: Beginning of table name to look for.

$count: (optional) Whether or not to assert that there are tables that match the specified base table. Defaults to TRUE.

1 call to ModuleTestBase::assertTableCount()
DependencyTest::testEnableWithoutDependency in core/modules/system/tests/src/Functional/Module/DependencyTest.php
Attempts to enable the Content Translation module without Language enabled.

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 assertTableCount($base_table, $count = TRUE) {
  $connection = Database::getConnection();
  $tables = $connection
    ->schema()
    ->findTables($connection
    ->prefixTables('{' . $base_table . '}') . '%');
  if ($count) {
    return $this
      ->assertNotEmpty($tables, new FormattableMarkup('Tables matching "@base_table" found.', [
      '@base_table' => $base_table,
    ]));
  }
  return $this
    ->assertEmpty($tables, new FormattableMarkup('Tables matching "@base_table" not found.', [
    '@base_table' => $base_table,
  ]));
}