DefaultTableMappingIntegrationTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Drupal\KernelTests\Core\Entity;
  3. use Drupal\Core\Field\BaseFieldDefinition;
  4. use Drupal\Core\Field\FieldStorageDefinitionInterface;
  5. /**
  6. * Tests the default table mapping class for content entities stored in SQL.
  7. *
  8. * @see \Drupal\Core\Entity\Sql\DefaultTableMapping
  9. * @see \Drupal\Core\Entity\Sql\TableMappingInterface
  10. *
  11. * @coversDefaultClass \Drupal\Core\Entity\Sql\DefaultTableMapping
  12. * @group Entity
  13. */
  14. class DefaultTableMappingIntegrationTest extends EntityKernelTestBase {
  15. /**
  16. * The table mapping for the tested entity type.
  17. *
  18. * @var \Drupal\Core\Entity\Sql\TableMappingInterface
  19. */
  20. protected $tableMapping;
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static $modules = ['entity_test_extra'];
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function setUp() {
  29. parent::setUp();
  30. // Setup some fields for entity_test_extra to create.
  31. $definitions['multivalued_base_field'] = BaseFieldDefinition::create('string')
  32. ->setName('multivalued_base_field')
  33. ->setTargetEntityTypeId('entity_test_mulrev')
  34. ->setTargetBundle('entity_test_mulrev')
  35. ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  36. $this->state->set('entity_test_mulrev.additional_base_field_definitions', $definitions);
  37. $this->entityManager->clearCachedDefinitions();
  38. $this->tableMapping = $this->entityManager->getStorage('entity_test_mulrev')->getTableMapping();
  39. }
  40. /**
  41. * Tests DefaultTableMapping::getFieldTableName().
  42. *
  43. * @covers ::getFieldTableName
  44. */
  45. public function testGetFieldTableName() {
  46. // Test the field table name for a single-valued base field, which is stored
  47. // in the entity's base table.
  48. $expected = 'entity_test_mulrev';
  49. $this->assertEquals($this->tableMapping->getFieldTableName('uuid'), $expected);
  50. // Test the field table name for a translatable and revisionable base field,
  51. // which is stored in the entity's data table.
  52. $expected = 'entity_test_mulrev_property_data';
  53. $this->assertEquals($this->tableMapping->getFieldTableName('name'), $expected);
  54. // Test the field table name for a multi-valued base field, which is stored
  55. // in a dedicated table.
  56. $expected = 'entity_test_mulrev__multivalued_base_field';
  57. $this->assertEquals($this->tableMapping->getFieldTableName('multivalued_base_field'), $expected);
  58. }
  59. }