You are here

public function SqlContentEntityStorageSchemaTest::testGetSchemaRevisionable in Drupal 8

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 411

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetSchemaRevisionable() {
  $this->entityType = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityType')
    ->setConstructorArgs([
    [
      'id' => 'entity_test',
      'entity_keys' => [
        'id' => 'id',
        'revision' => 'revision_id',
      ],
    ],
  ])
    ->setMethods([
    'getRevisionMetadataKeys',
  ])
    ->getMock();
  $this->entityType
    ->expects($this
    ->any())
    ->method('getRevisionMetadataKeys')
    ->will($this
    ->returnValue([]));
  $this->storage
    ->expects($this
    ->exactly(9))
    ->method('getRevisionTable')
    ->will($this
    ->returnValue('entity_test_revision'));
  $this
    ->setUpStorageDefinition('revision_id', [
    'columns' => [
      'value' => [
        'type' => 'int',
      ],
    ],
  ]);
  $expected = [
    'entity_test' => [
      'description' => 'The base table for entity_test entities.',
      'fields' => [
        'id' => [
          'type' => 'serial',
          'not null' => TRUE,
        ],
        'revision_id' => [
          'type' => 'int',
          'not null' => FALSE,
        ],
      ],
      'primary key' => [
        'id',
      ],
      'unique keys' => [
        'entity_test__revision_id' => [
          'revision_id',
        ],
      ],
      'indexes' => [],
      'foreign keys' => [
        'entity_test__revision' => [
          'table' => 'entity_test_revision',
          'columns' => [
            'revision_id' => 'revision_id',
          ],
        ],
      ],
    ],
    'entity_test_revision' => [
      'description' => 'The revision table for entity_test entities.',
      'fields' => [
        'id' => [
          'type' => 'int',
          'not null' => TRUE,
        ],
        'revision_id' => [
          'type' => 'serial',
          'not null' => TRUE,
        ],
      ],
      'primary key' => [
        'revision_id',
      ],
      'unique keys' => [],
      'indexes' => [
        'entity_test__id' => [
          'id',
        ],
      ],
      'foreign keys' => [
        'entity_test__revisioned' => [
          'table' => 'entity_test',
          'columns' => [
            'id' => 'id',
          ],
        ],
      ],
    ],
  ];
  $this
    ->setUpStorageSchema($expected);
  $table_mapping = new TestSqlContentDefaultTableMapping($this->entityType, $this->storageDefinitions);
  $table_mapping
    ->setFieldNames('entity_test', array_keys($this->storageDefinitions));
  $table_mapping
    ->setFieldNames('entity_test_revision', array_keys($this->storageDefinitions));
  $this->storageSchema
    ->expects($this
    ->any())
    ->method('getTableMapping')
    ->will($this
    ->returnValue($table_mapping));
  $this->storageSchema
    ->onEntityTypeCreate($this->entityType);
}