8f945b3cba90bb5454119a5a42bf89e7820f2ae8
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Entity / DefaultTableMappingIntegrationTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Entity;
4
5 use Drupal\Core\Field\BaseFieldDefinition;
6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
7
8 /**
9  * Tests the default table mapping class for content entities stored in SQL.
10  *
11  * @see \Drupal\Core\Entity\Sql\DefaultTableMapping
12  * @see \Drupal\Core\Entity\Sql\TableMappingInterface
13  *
14  * @coversDefaultClass \Drupal\Core\Entity\Sql\DefaultTableMapping
15  * @group Entity
16  */
17 class DefaultTableMappingIntegrationTest extends EntityKernelTestBase {
18
19   /**
20    * The table mapping for the tested entity type.
21    *
22    * @var \Drupal\Core\Entity\Sql\TableMappingInterface
23    */
24   protected $tableMapping;
25
26   /**
27    * {@inheritdoc}
28    */
29   public static $modules = ['entity_test_extra'];
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp() {
35     parent::setUp();
36
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);
44
45     $this->entityManager->clearCachedDefinitions();
46     $this->tableMapping = $this->entityManager->getStorage('entity_test_mulrev')->getTableMapping();
47   }
48
49   /**
50    * Tests DefaultTableMapping::getFieldTableName().
51    *
52    * @covers ::getFieldTableName
53    */
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);
59
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);
64
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);
69   }
70
71 }