/** * Tests the schema for revisionable, translatable entities. * * @covers ::__construct() * @covers ::getSchema() * @covers ::getTables() * @covers ::initializeDataTable() * @covers ::addTableDefaults() * @covers ::getEntityIndexName() * @covers ::initializeRevisionDataTable() * @covers ::processRevisionDataTable() */ public function testGetSchemaRevisionableTranslatable() { $this->entityType = new ContentEntityType(array('id' => 'entity_test', 'entity_keys' => array('id' => 'id', 'revision' => 'revision_id'))); $this->storage->expects($this->exactly(3))->method('getRevisionTable')->will($this->returnValue('entity_test_revision')); $this->storage->expects($this->once())->method('getDataTable')->will($this->returnValue('entity_test_field_data')); $this->storage->expects($this->once())->method('getRevisionDataTable')->will($this->returnValue('entity_test_revision_field_data')); $this->setUpStorageDefinition('revision_id', array('columns' => array('value' => array('type' => 'int')))); $this->setUpStorageDefinition('langcode', array('columns' => array('value' => array('type' => 'varchar')))); $this->setUpSchemaHandler(); $table_mapping = new DefaultTableMapping($this->storageDefinitions); $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); $table_mapping->setFieldNames('entity_test_revision', array_keys($this->storageDefinitions)); $table_mapping->setFieldNames('entity_test_field_data', array_keys($this->storageDefinitions)); $table_mapping->setFieldNames('entity_test_revision_field_data', array_keys($this->storageDefinitions)); $this->storage->expects($this->once())->method('getTableMapping')->will($this->returnValue($table_mapping)); $expected = array('entity_test' => array('description' => 'The base table for entity_test entities.', 'fields' => array('id' => array('description' => 'The id field.', 'type' => 'serial', 'not null' => TRUE), 'revision_id' => array('description' => 'The revision_id field.', 'type' => 'int'), 'langcode' => array('description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE)), 'primary key' => array('id'), 'unique keys' => array('entity_test__revision_id' => array('revision_id')), 'indexes' => array(), 'foreign keys' => array('entity_test__revision' => array('table' => 'entity_test_revision', 'columns' => array('revision_id' => 'revision_id')))), 'entity_test_revision' => array('description' => 'The revision table for entity_test entities.', 'fields' => array('id' => array('description' => 'The id field.', 'type' => 'int', 'not null' => TRUE), 'revision_id' => array('description' => 'The revision_id field.', 'type' => 'serial'), 'langcode' => array('description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE)), 'primary key' => array('revision_id'), 'unique keys' => array(), 'indexes' => array('entity_test__id' => array('id')), 'foreign keys' => array('entity_test__revisioned' => array('table' => 'entity_test', 'columns' => array('id' => 'id')))), 'entity_test_field_data' => array('description' => 'The data table for entity_test entities.', 'fields' => array('id' => array('description' => 'The id field.', 'type' => 'int', 'not null' => TRUE), 'revision_id' => array('description' => 'The revision_id field.', 'type' => 'int'), 'langcode' => array('description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE)), 'primary key' => array('id', 'langcode'), 'unique keys' => array(), 'indexes' => array('entity_test__revision_id' => array('revision_id')), 'foreign keys' => array('entity_test' => array('table' => 'entity_test', 'columns' => array('id' => 'id')))), 'entity_test_revision_field_data' => array('description' => 'The revision data table for entity_test entities.', 'fields' => array('id' => array('description' => 'The id field.', 'type' => 'int', 'not null' => TRUE), 'revision_id' => array('description' => 'The revision_id field.', 'type' => 'int'), 'langcode' => array('description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE)), 'primary key' => array('revision_id', 'langcode'), 'unique keys' => array(), 'indexes' => array(), 'foreign keys' => array('entity_test' => array('table' => 'entity_test', 'columns' => array('id' => 'id')), 'entity_test__revision' => array('table' => 'entity_test_revision', 'columns' => array('revision_id' => 'revision_id'))))); $actual = $this->schemaHandler->getSchema(); $this->assertEquals($expected, $actual); }