function SqlContentEntityStorageSchemaTest::setUpStorageSchema

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

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

protected function setUpStorageSchema(array $expected = []) {
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getDefinition')
        ->with($this->entityType
        ->id())
        ->will($this->returnValue($this->entityType));
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getActiveDefinition')
        ->with($this->entityType
        ->id())
        ->will($this->returnValue($this->entityType));
    $this->entityFieldManager
        ->expects($this->any())
        ->method('getFieldStorageDefinitions')
        ->with($this->entityType
        ->id())
        ->will($this->returnValue($this->storageDefinitions));
    $this->entityFieldManager
        ->expects($this->any())
        ->method('getActiveFieldStorageDefinitions')
        ->with($this->entityType
        ->id())
        ->will($this->returnValue($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;
        }))
            ->will($this->returnCallback(function () use (&$invocation_count) {
            $invocation_count++;
        }));
    }
    $connection = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')
        ->disableOriginalConstructor()
        ->getMock();
    $connection->expects($this->any())
        ->method('schema')
        ->will($this->returnValue($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,
        $this->entityType,
        $this->storage,
        $connection,
        $this->entityFieldManager,
        $this->entityLastInstalledSchemaRepository,
    ])
        ->setMethods([
        'installedStorageSchema',
        'loadEntitySchemaData',
        'hasSharedTableNameChanges',
        'isTableEmpty',
        'getTableMapping',
    ])
        ->getMock();
    $this->storageSchema
        ->expects($this->any())
        ->method('installedStorageSchema')
        ->will($this->returnValue($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.