diff --git a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php index 78e6c06..d6ca5db 100644 --- a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php +++ b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php @@ -247,8 +247,8 @@ public static function create(ContentEntityTypeInterface $entity_type, array $st /** * Gets the base table name. * - * @return string|null - * The table name. + * @return string + * The base table name. * * @internal */ diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index d8ab13c..376b556 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -15,6 +15,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\Query\QueryFactoryInterface; +use Drupal\Core\Entity\Sql\DefaultTableMapping; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; use Drupal\Core\Language\Language; use Drupal\Tests\UnitTestCase; @@ -313,6 +314,51 @@ public function providerTestGetRevisionDataTable() { } /** + * Tests that setting a new table mapping also updates the table names. + * + * @covers ::setTableMapping + */ + public function testSetTableMapping() { + $this->entityType->expects($this->any()) + ->method('isRevisionable') + ->will($this->returnValue(FALSE)); + $this->entityType->expects($this->any()) + ->method('isTranslatable') + ->will($this->returnValue(FALSE)); + $this->entityType->expects($this->any()) + ->method('getRevisionMetadataKeys') + ->willReturn([]); + + $this->setUpEntityStorage(); + + $this->assertSame('entity_test', $this->entityStorage->getBaseTable()); + $this->assertNull($this->entityStorage->getRevisionTable()); + $this->assertNull($this->entityStorage->getDataTable()); + $this->assertNull($this->entityStorage->getRevisionDataTable()); + + // Change the entity type definition and instantiate a new table mapping + // with it. + $updated_entity_type = $this->createMock('Drupal\Core\Entity\ContentEntityTypeInterface'); + $updated_entity_type->expects($this->any()) + ->method('id') + ->will($this->returnValue($this->entityTypeId)); + $updated_entity_type->expects($this->any()) + ->method('isRevisionable') + ->will($this->returnValue(TRUE)); + $updated_entity_type->expects($this->any()) + ->method('isTranslatable') + ->will($this->returnValue(TRUE)); + + $table_mapping = new DefaultTableMapping($updated_entity_type, []); + $this->entityStorage->setTableMapping($table_mapping); + + $this->assertSame('entity_test', $this->entityStorage->getBaseTable()); + $this->assertSame('entity_test_revision', $this->entityStorage->getRevisionTable()); + $this->assertSame('entity_test_field_data', $this->entityStorage->getDataTable()); + $this->assertSame('entity_test_field_revision', $this->entityStorage->getRevisionDataTable()); + } + + /** * Tests ContentEntityDatabaseStorage::onEntityTypeCreate(). * * @covers ::__construct