diff -u b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php --- b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -891,8 +891,83 @@ ), ), ), - $entity_type_id . '_revision__' . $field_name => array( - 'description' => "Revision archive storage for $entity_type_id field $field_name.", + ); + + $this->setUpStorageSchema($expected); + + $table_mapping = new DefaultTableMapping($this->storageDefinitions); + $table_mapping->setFieldNames($entity_type_id, array_keys($this->storageDefinitions)); + $table_mapping->setExtraColumns($entity_type_id, array('default_langcode')); + + $this->storage->expects($this->any()) + ->method('getTableMapping') + ->will($this->returnValue($table_mapping)); + + $this->storageSchema->onFieldStorageDefinitionCreate($field_storage); + } + + /** + * Tests the schema for a field dedicated table for an entity with a string identifier. + * + * @covers ::getDedicatedTableSchema() + * @covers ::createDedicatedTableSchema() + */ + public function testDedicatedTableSchemaForEntityWithStringIdentifier() { + $entity_type_id = 'entity_test'; + $this->entityType = new ContentEntityType(array( + 'id' => 'entity_test', + 'entity_keys' => array('id' => 'id'), + )); + + // Setup a field having a dedicated schema. + $field_name = $this->getRandomGenerator()->name(); + $this->setUpStorageDefinition($field_name, array( + 'columns' => array( + 'shape' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => FALSE, + ), + 'color' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => FALSE, + ), + ), + 'foreign keys' => array( + 'color' => array( + 'table' => 'color', + 'columns' => array( + 'color' => 'id' + ), + ), + ), + 'unique keys' => array(), + 'indexes' => array(), + )); + + $field_storage = $this->storageDefinitions[$field_name]; + $field_storage + ->expects($this->any()) + ->method('getType') + ->will($this->returnValue('shape')); + $field_storage + ->expects($this->any()) + ->method('getTargetEntityTypeId') + ->will($this->returnValue($entity_type_id)); + $field_storage + ->expects($this->any()) + ->method('isMultiple') + ->will($this->returnValue(TRUE)); + + $this->storageDefinitions['id'] + ->expects($this->any()) + ->method('getType') + ->will($this->returnValue('string')); + + $expected = array( + $entity_type_id . '__' . $field_name => array( + 'description' => "Data storage for $entity_type_id field $field_name.", 'fields' => array( 'bundle' => array( 'type' => 'varchar', @@ -909,16 +984,16 @@ 'description' => 'A boolean indicating whether this data item has been deleted', ), 'entity_id' => array( - 'type' => 'int', - 'unsigned' => true, + 'type' => 'varchar', + 'length' => 128, 'not null' => true, 'description' => 'The entity id this data is attached to', ), 'revision_id' => array( - 'type' => 'int', - 'unsigned' => true, + 'type' => 'varchar', + 'length' => 128, 'not null' => true, - 'description' => 'The entity revision id this data is attached to', + 'description' => 'The entity revision id this data is attached to, which for an unversioned entity type is the same as the entity id', ), 'langcode' => array( 'type' => 'varchar', @@ -944,7 +1019,7 @@ 'not null' => false, ), ), - 'primary key' => array('entity_id', 'revision_id', 'deleted', 'delta', 'langcode'), + 'primary key' => array('entity_id', 'deleted', 'delta', 'langcode'), 'indexes' => array( 'bundle' => array('bundle'), 'deleted' => array('deleted'), diff -u b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php --- b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -927,101 +927,6 @@ } /** - * Tests field SQL schema generation for an entity with a string identifier. - * - * @covers SqlContentEntityStorageSchema::onFieldStorageDefinitionCreate() - */ - public function testFieldSqlSchemaForEntityWithStringIdentifier() { - $field_type_manager = $this->getMock('Drupal\Core\Field\FieldTypePluginManagerInterface'); - - $this->container->set('plugin.manager.field.field_type', $field_type_manager); - $this->container->set('entity.manager', $this->entityManager); - - $this->entityType->expects($this->any()) - ->method('getKey') - ->will($this->returnValueMap(array( - array('id', 'id'), - array('revision', 'revision'), - ))); - $this->entityType->expects($this->any()) - ->method('isRevisionable') - ->will($this->returnValue(TRUE)); - - $field_type_manager->expects($this->exactly(2)) - ->method('getDefaultSettings') - ->will($this->returnValue(array())); - $field_type_manager->expects($this->exactly(2)) - ->method('getDefaultInstanceSettings') - ->will($this->returnValue(array())); - - $this->fieldDefinitions['id'] = BaseFieldDefinition::create('string') - ->setName('id'); - $this->fieldDefinitions['revision'] = BaseFieldDefinition::create('string') - ->setName('revision'); - - $this->entityManager->expects($this->any()) - ->method('getDefinition') - ->with('test_entity') - ->will($this->returnValue($this->entityType)); - $this->entityManager->expects($this->any()) - ->method('getStorageFieldDefinitions') - ->will($this->returnValue($this->fieldDefinitions)); - - // Define a field definition for a test_field field. - $field_storage = $this->getMock('\Drupal\field\FieldStorageConfigInterface'); - $field_storage->deleted = FALSE; - - $field_storage->expects($this->any()) - ->method('getName') - ->will($this->returnValue('test_field')); - - $field_storage->expects($this->any()) - ->method('getTargetEntityTypeId') - ->will($this->returnValue('test_entity')); - - $field_schema = array( - 'columns' => array( - 'value' => array( - 'type' => 'varchar', - 'length' => 10, - 'not null' => FALSE, - ), - ), - 'unique keys' => array(), - 'indexes' => array(), - 'foreign keys' => array(), - ); - $field_storage->expects($this->any()) - ->method('getSchema') - ->will($this->returnValue($field_schema)); - - $this->setUpEntityStorage(); - - $schema = $this->getMockBuilder('\Drupal\Core\Database\Schema') - ->disableOriginalConstructor() - ->getMock(); - - $schema->expects($this->exactly(2)) - ->method('createTable') - ->with(); - ; - - $this->connection - ->expects($this->any()) - ->method('schema') - ->will($this->returnValue($schema)); - - $schema_handler = new SqlContentEntityStorageSchema($this->entityManager, $this->entityType, $this->entityStorage, $this->connection); - $schema_handler->onFieldStorageDefinitionCreate($field_storage); - - // Make sure that the entity_id schema field if of type varchar. - // $schema['test_entity__test_field']['fields']['entity_id']['type'] - $this->assertEquals('varchar', 'varchar'); - // $schema['test_entity__test_field']['fields']['revision_id']['type'] - $this->assertEquals('varchar', 'varchar'); - } - - /** * @covers ::create() */ public function testCreate() {