3 namespace Drupal\KernelTests\Core\Entity;
5 use Drupal\Core\Field\BaseFieldDefinition;
6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
9 * Tests the default table mapping class for content entities stored in SQL.
11 * @see \Drupal\Core\Entity\Sql\DefaultTableMapping
12 * @see \Drupal\Core\Entity\Sql\TableMappingInterface
14 * @coversDefaultClass \Drupal\Core\Entity\Sql\DefaultTableMapping
17 class DefaultTableMappingIntegrationTest extends EntityKernelTestBase {
20 * The table mapping for the tested entity type.
22 * @var \Drupal\Core\Entity\Sql\TableMappingInterface
24 protected $tableMapping;
29 public static $modules = ['entity_test_extra'];
34 protected function setUp() {
37 // Setup some fields for entity_test_extra to create.
38 $definitions['multivalued_base_field'] = BaseFieldDefinition::create('string')
39 ->setName('multivalued_base_field')
40 ->setTargetEntityTypeId('entity_test_mulrev')
41 ->setTargetBundle('entity_test_mulrev')
42 ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
43 $this->state->set('entity_test_mulrev.additional_base_field_definitions', $definitions);
45 $this->entityManager->clearCachedDefinitions();
46 $this->tableMapping = $this->entityManager->getStorage('entity_test_mulrev')->getTableMapping();
50 * Tests DefaultTableMapping::getFieldTableName().
52 * @covers ::getFieldTableName
54 public function testGetFieldTableName() {
55 // Test the field table name for a single-valued base field, which is stored
56 // in the entity's base table.
57 $expected = 'entity_test_mulrev';
58 $this->assertEquals($this->tableMapping->getFieldTableName('uuid'), $expected);
60 // Test the field table name for a translatable and revisionable base field,
61 // which is stored in the entity's data table.
62 $expected = 'entity_test_mulrev_property_data';
63 $this->assertEquals($this->tableMapping->getFieldTableName('name'), $expected);
65 // Test the field table name for a multi-valued base field, which is stored
66 // in a dedicated table.
67 $expected = 'entity_test_mulrev__multivalued_base_field';
68 $this->assertEquals($this->tableMapping->getFieldTableName('multivalued_base_field'), $expected);