You are here

public function SqlContentEntityStorageSchemaTest::testGetSchemaRevisionableTranslatable in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::testGetSchemaRevisionableTranslatable()

Tests the schema for revisionable, translatable entities.

@covers ::__construct @covers ::getEntitySchemaTables @covers ::initializeDataTable @covers ::addTableDefaults @covers ::getEntityIndexName @covers ::initializeRevisionDataTable @covers ::processRevisionDataTable

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php, line 602
Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest.

Class

SqlContentEntityStorageSchemaTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetSchemaRevisionableTranslatable() {
  $this->entityType = new ContentEntityType(array(
    'id' => 'entity_test',
    'entity_keys' => array(
      'id' => 'id',
      'revision' => 'revision_id',
      'langcode' => 'langcode',
    ),
  ));
  $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
    ->setUpStorageDefinition('default_langcode', array(
    'columns' => array(
      'value' => array(
        'type' => 'int',
        'size' => 'tiny',
      ),
    ),
  ));
  $expected = array(
    'entity_test' => array(
      'description' => 'The base table for entity_test entities.',
      'fields' => array(
        'id' => array(
          'type' => 'serial',
          'not null' => TRUE,
        ),
        'revision_id' => array(
          'type' => 'int',
          'not null' => FALSE,
        ),
        'langcode' => array(
          '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(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'revision_id' => array(
          'type' => 'serial',
          'not null' => TRUE,
        ),
        'langcode' => array(
          '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(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'revision_id' => array(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'langcode' => array(
          'type' => 'varchar',
          'not null' => TRUE,
        ),
        'default_langcode' => array(
          'type' => 'int',
          'size' => 'tiny',
          'not null' => true,
        ),
      ),
      'primary key' => array(
        'id',
        'langcode',
      ),
      'unique keys' => array(),
      'indexes' => array(
        'entity_test__revision_id' => array(
          'revision_id',
        ),
        'entity_test__id__default_langcode__langcode' => array(
          0 => 'id',
          1 => 'default_langcode',
          2 => 'langcode',
        ),
      ),
      '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(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'revision_id' => array(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'langcode' => array(
          'type' => 'varchar',
          'not null' => TRUE,
        ),
        'default_langcode' => array(
          'type' => 'int',
          'size' => 'tiny',
          'not null' => true,
        ),
      ),
      'primary key' => array(
        'revision_id',
        'langcode',
      ),
      'unique keys' => array(),
      'indexes' => array(
        'entity_test__id__default_langcode__langcode' => array(
          0 => 'id',
          1 => 'default_langcode',
          2 => 'langcode',
        ),
      ),
      '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',
          ),
        ),
      ),
    ),
  );
  $this
    ->setUpStorageSchema($expected);
  $table_mapping = new DefaultTableMapping($this->entityType, $this->storageDefinitions);
  $non_data_fields = array_keys($this->storageDefinitions);
  unset($non_data_fields[array_search('default_langcode', $non_data_fields)]);
  $table_mapping
    ->setFieldNames('entity_test', $non_data_fields);
  $table_mapping
    ->setFieldNames('entity_test_revision', $non_data_fields);
  $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
    ->any())
    ->method('getTableMapping')
    ->will($this
    ->returnValue($table_mapping));
  $this->storageSchema
    ->onEntityTypeCreate($this->entityType);
}