You are here

public function SqlContentEntityStorageSchemaTest::testGetSchemaRevisionable 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::testGetSchemaRevisionable()

Tests the schema for revisionable, non-translatable entities.

@covers ::__construct @covers ::getEntitySchemaTables @covers ::initializeBaseTable @covers ::initializeRevisionTable @covers ::addTableDefaults @covers ::getEntityIndexName @covers ::processRevisionTable @covers ::processIdentifierSchema

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php, line 396
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 testGetSchemaRevisionable() {
  $this->entityType = new ContentEntityType(array(
    'id' => 'entity_test',
    'entity_keys' => array(
      'id' => 'id',
      'revision' => 'revision_id',
    ),
  ));
  $this->storage
    ->expects($this
    ->exactly(2))
    ->method('getRevisionTable')
    ->will($this
    ->returnValue('entity_test_revision'));
  $this
    ->setUpStorageDefinition('revision_id', array(
    'columns' => array(
      'value' => array(
        'type' => 'int',
      ),
    ),
  ));
  $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,
        ),
      ),
      '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,
        ),
      ),
      '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',
          ),
        ),
      ),
    ),
  );
  $this
    ->setUpStorageSchema($expected);
  $table_mapping = new DefaultTableMapping($this->entityType, $this->storageDefinitions);
  $table_mapping
    ->setFieldNames('entity_test', array_keys($this->storageDefinitions));
  $table_mapping
    ->setFieldNames('entity_test_revision', array_keys($this->storageDefinitions));
  $this->storage
    ->expects($this
    ->any())
    ->method('getTableMapping')
    ->will($this
    ->returnValue($table_mapping));
  $this->storageSchema
    ->onEntityTypeCreate($this->entityType);
}