function SqlContentEntityStorageSchemaTest::testRequiresEntityDataMigration

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

@covers ::requiresEntityDataMigration

@dataProvider providerTestRequiresEntityDataMigration

File

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

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testRequiresEntityDataMigration(string $storage_class, bool|null $original_storage_has_data, bool $shared_table_structure_changed, bool $migration_required) : void {
    $this->entityType = new ContentEntityType([
        'id' => 'entity_test',
        'entity_keys' => [
            'id' => 'id',
        ],
    ]);
    $this->storage
        ->expects($this->exactly(is_null($original_storage_has_data) || !$shared_table_structure_changed ? 0 : 1))
        ->method('hasData')
        ->willReturn($original_storage_has_data);
    $connection = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')
        ->disableOriginalConstructor()
        ->getMock();
    $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',
        'hasSharedTableStructureChange',
    ])
        ->getMock();
    $updated_entity_type_definition = $this->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
    $updated_entity_type_definition->expects($this->any())
        ->method('getStorageClass')
        ->willReturn('\\Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorageSchema');
    $original_entity_type_definition = $this->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
    $original_entity_type_definition->expects($this->any())
        ->method('getStorageClass')
        ->willReturn($storage_class);
    $this->storageSchema
        ->expects($this->any())
        ->method('hasSharedTableStructureChange')
        ->with($updated_entity_type_definition, $original_entity_type_definition)
        ->willReturn($shared_table_structure_changed);
    $this->assertEquals($migration_required, $this->storageSchema
        ->requiresEntityDataMigration($updated_entity_type_definition, $original_entity_type_definition));
}

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