function SqlContentEntityStorageSchemaTest::testGetSchemaRevisionable

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::testGetSchemaRevisionable()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::testGetSchemaRevisionable()
  3. 11.x 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 ::processIdentifierSchema

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php, line 413

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetSchemaRevisionable() : void {
    $this->entityType = $this->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityType')
        ->setConstructorArgs([
        [
            'id' => 'entity_test',
            'entity_keys' => [
                'id' => 'id',
                'revision' => 'revision_id',
            ],
        ],
    ])
        ->onlyMethods([
        'getRevisionMetadataKeys',
    ])
        ->getMock();
    $this->entityType
        ->expects($this->any())
        ->method('getRevisionMetadataKeys')
        ->willReturn([]);
    $this->storage
        ->expects($this->exactly(9))
        ->method('getRevisionTable')
        ->willReturn('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')
        ->willReturn($table_mapping);
    $this->storageSchema
        ->onEntityTypeCreate($this->entityType);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.