+ /**
+ * 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());
+ }
+