You are here

public function SqlContentEntityStorageSchemaTest::testRequiresEntityDataMigration in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 1137
Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest.

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(array(
    'id' => 'entity_test',
    'entity_keys' => array(
      'id' => 'id',
    ),
  ));
  $original_storage = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage')
    ->disableOriginalConstructor()
    ->getMock();
  $original_storage
    ->expects($this
    ->exactly(is_null($original_storage_has_data) || !$shared_table_structure_changed ? 0 : 1))
    ->method('hasData')
    ->willReturn($original_storage_has_data);

  // Assert hasData() is never called on the new storage definition.
  $this->storage
    ->expects($this
    ->never())
    ->method('hasData');
  $connection = $this
    ->getMockBuilder('Drupal\\Core\\Database\\Connection')
    ->disableOriginalConstructor()
    ->getMock();
  $this->entityManager
    ->expects($this
    ->any())
    ->method('createHandlerInstance')
    ->willReturn($original_storage);
  $this->storageSchema = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorageSchema')
    ->setConstructorArgs(array(
    $this->entityManager,
    $this->entityType,
    $this->storage,
    $connection,
  ))
    ->setMethods(array(
    '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));
}