function SqlContentEntityStorageSchemaTest::setUpStorageSchema

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::setUpStorageSchema()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::setUpStorageSchema()
  3. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::setUpStorageSchema()

Sets up the storage schema object to test.

This uses the field definitions set in $this->storageDefinitions.

Parameters

array $expected: (optional) An associative array describing the expected entity schema to be created. Defaults to expecting nothing.

8 calls to SqlContentEntityStorageSchemaTest::setUpStorageSchema()
SqlContentEntityStorageSchemaTest::testDedicatedTableSchema in core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
Tests the schema for a field dedicated table.
SqlContentEntityStorageSchemaTest::testDedicatedTableSchemaForEntityWithStringIdentifier in core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
Tests the schema for a field dedicated table for an entity with a string identifier.
SqlContentEntityStorageSchemaTest::testGetSchemaBase in core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
Tests the schema for non-revisionable, non-translatable entities.
SqlContentEntityStorageSchemaTest::testGetSchemaRevisionable in core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
Tests the schema for revisionable, non-translatable entities.
SqlContentEntityStorageSchemaTest::testGetSchemaRevisionableTranslatable in core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
Tests the schema for revisionable, translatable entities.

... See full list

File

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

Class

SqlContentEntityStorageSchemaTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Sql%21SqlContentEntityStorageSchema.php/class/SqlContentEntityStorageSchema/11.x" title="Defines a schema handler that supports revisionable, translatable entities." class="local">\Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema</a> @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

protected function setUpStorageSchema(array $expected = []) {
    $this->entityTypeManager
        ->getDefinition($this->entityType
        ->id())
        ->willReturn($this->entityType);
    $this->entityTypeManager
        ->getActiveDefinition($this->entityType
        ->id())
        ->willReturn($this->entityType);
    $this->entityFieldManager
        ->getFieldStorageDefinitions($this->entityType
        ->id())
        ->willReturn($this->storageDefinitions);
    $this->entityFieldManager
        ->getActiveFieldStorageDefinitions($this->entityType
        ->id())
        ->willReturn($this->storageDefinitions);
    $this->dbSchemaHandler = $this->getMockBuilder('Drupal\\Core\\Database\\Schema')
        ->disableOriginalConstructor()
        ->getMock();
    if ($expected) {
        $invocation_count = 0;
        $expected_table_names = array_keys($expected);
        $expected_table_schemas = array_values($expected);
        $this->dbSchemaHandler
            ->expects($this->any())
            ->method('createTable')
            ->with($this->callback(function ($table_name) use (&$invocation_count, $expected_table_names) {
            return $expected_table_names[$invocation_count] == $table_name;
        }), $this->callback(function ($table_schema) use (&$invocation_count, $expected_table_schemas) {
            return $expected_table_schemas[$invocation_count] == $table_schema;
        }))
            ->willReturnCallback(function () use (&$invocation_count) {
            $invocation_count++;
        });
    }
    $connection = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')
        ->disableOriginalConstructor()
        ->getMock();
    $connection->expects($this->any())
        ->method('schema')
        ->willReturn($this->dbSchemaHandler);
    $key_value = $this->createMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreInterface');
    $this->entityLastInstalledSchemaRepository
        ->expects($this->any())
        ->method('getLastInstalledDefinition')
        ->willReturn($this->entityType);
    $this->entityLastInstalledSchemaRepository
        ->expects($this->any())
        ->method('getLastInstalledFieldStorageDefinitions')
        ->willReturn($this->storageDefinitions);
    $this->storageSchema = $this->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorageSchema')
        ->setConstructorArgs([
        $this->entityTypeManager
            ->reveal(),
        $this->entityType,
        $this->storage,
        $connection,
        $this->entityFieldManager
            ->reveal(),
        $this->entityLastInstalledSchemaRepository,
    ])
        ->onlyMethods([
        'installedStorageSchema',
        'loadEntitySchemaData',
        'hasSharedTableNameChanges',
        'isTableEmpty',
        'getTableMapping',
    ])
        ->getMock();
    $this->storageSchema
        ->expects($this->any())
        ->method('installedStorageSchema')
        ->willReturn($key_value);
    $this->storageSchema
        ->expects($this->any())
        ->method('isTableEmpty')
        ->willReturn(FALSE);
}

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