You are here

public function DefaultTableMappingIntegrationTest::testGetTableNames in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/DefaultTableMappingIntegrationTest.php \Drupal\KernelTests\Core\Entity\DefaultTableMappingIntegrationTest::testGetTableNames()

Tests DefaultTableMapping::getTableNames().

@covers ::getTableNames

File

core/tests/Drupal/KernelTests/Core/Entity/DefaultTableMappingIntegrationTest.php, line 85

Class

DefaultTableMappingIntegrationTest
Tests the default table mapping class for content entities stored in SQL.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testGetTableNames() {
  $storage_definitions = \Drupal::service('entity_field.manager')
    ->getFieldStorageDefinitions('entity_test_mulrev');
  $dedicated_data_table = $this->tableMapping
    ->getDedicatedDataTableName($storage_definitions['multivalued_base_field']);
  $dedicated_revision_table = $this->tableMapping
    ->getDedicatedRevisionTableName($storage_definitions['multivalued_base_field']);

  // Check that both the data and the revision tables exist for a multi-valued
  // base field.
  $database_schema = \Drupal::database()
    ->schema();
  $this
    ->assertTrue($database_schema
    ->tableExists($dedicated_data_table));
  $this
    ->assertTrue($database_schema
    ->tableExists($dedicated_revision_table));

  // Check that the table mapping contains both the data and the revision
  // tables exist for a multi-valued base field.
  $expected = [
    'entity_test_mulrev',
    'entity_test_mulrev_property_data',
    'entity_test_mulrev_revision',
    'entity_test_mulrev_property_revision',
    $dedicated_data_table,
    $dedicated_revision_table,
  ];
  $this
    ->assertEquals($expected, $this->tableMapping
    ->getTableNames());
}