You are here

public function SqlContentEntityStorageSchemaTest::testRequiresEntityDataMigration in Drupal 8

@covers ::requiresEntityDataMigration

@dataProvider providerTestRequiresEntityDataMigration

File

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

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testRequiresEntityDataMigration($updated_entity_type_definition, $original_entity_type_definition, $original_storage_has_data, $shared_table_structure_changed, $migration_required) {
  $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,
    $this->entityType,
    $this->storage,
    $connection,
    $this->entityFieldManager,
    $this->entityLastInstalledSchemaRepository,
  ])
    ->setMethods([
    'installedStorageSchema',
    'hasSharedTableStructureChange',
  ])
    ->getMock();
  $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));
}