/**
* The table mapping for the tested entity type.
*
- * @var \Drupal\Core\Entity\Sql\TableMappingInterface
+ * @var \Drupal\Core\Entity\Sql\DefaultTableMapping
*/
protected $tableMapping;
->setName('multivalued_base_field')
->setTargetEntityTypeId('entity_test_mulrev')
->setTargetBundle('entity_test_mulrev')
- ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
+ ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
+ // Base fields are non-translatable and non-revisionable by default, but
+ // we explicitly set these values here for extra clarity.
+ ->setTranslatable(FALSE)
+ ->setRevisionable(FALSE);
$this->state->set('entity_test_mulrev.additional_base_field_definitions', $definitions);
$this->entityManager->clearCachedDefinitions();
$this->tableMapping = $this->entityManager->getStorage('entity_test_mulrev')->getTableMapping();
+
+ // Ensure that the tables for the new field are created.
+ \Drupal::entityDefinitionUpdateManager()->applyUpdates();
}
/**
$this->assertEquals($this->tableMapping->getFieldTableName('multivalued_base_field'), $expected);
}
+ /**
+ * Tests DefaultTableMapping::getTableNames().
+ *
+ * @covers ::getTableNames
+ */
+ public function testGetTableNames() {
+ $storage_definitions = $this->entityManager->getFieldStorageDefinitions('entity_test_mulrev');
+ $dedicated_data_table = $this->tableMapping->getDedicatedDataTableName($storage_definitions['multivalued_base_field']);
+ $dedicated_revision_table = $this->tableMapping->getDedicatedRevisionTableName($storage_definitions['multivalued_base_field']);
+
+ // Check that both the data and the revision tables exist for a multi-valued
+ // base field.
+ $database_schema = \Drupal::database()->schema();
+ $this->assertTrue($database_schema->tableExists($dedicated_data_table));
+ $this->assertTrue($database_schema->tableExists($dedicated_revision_table));
+
+ // Check that the table mapping contains both the data and the revision
+ // tables exist for a multi-valued base field.
+ $expected = [
+ 'entity_test_mulrev',
+ 'entity_test_mulrev_property_data',
+ 'entity_test_mulrev_revision',
+ 'entity_test_mulrev_property_revision',
+ $dedicated_data_table,
+ $dedicated_revision_table,
+ ];
+ $this->assertEquals($expected, $this->tableMapping->getTableNames());
+ }
+
}