You are here

public function EntityReferenceRevisionsDestinationTest::testGetEntityForceRevision in Entity Reference Revisions 8

Tests get entity.

@dataProvider getEntityDataProviderForceRevision

@covers ::getEntity @covers ::rollback @covers ::rollbackNonTranslation

File

tests/src/Kernel/Plugin/migrate/destination/EntityReferenceRevisionsDestinationTest.php, line 248

Class

EntityReferenceRevisionsDestinationTest
Tests the migration destination plugin.

Namespace

Drupal\Tests\entity_reference_revisions\Kernel\Plugin\migrate\destination

Code

public function testGetEntityForceRevision(array $definition, array $expected) {

  /** @var \Drupal\migrate\Plugin\Migration $migration */
  $migration = $this->migrationPluginManager
    ->createStubMigration($definition);
  $migrationExecutable = new MigrateExecutable($migration, $this);

  /** @var \Drupal\Core\Entity\EntityStorageBase $storage */
  $storage = $this
    ->readAttribute($migration
    ->getDestinationPlugin(), 'storage');

  // Test inserting and updating by looping twice.
  for ($i = 0; $i < 2; $i++) {
    $migrationExecutable
      ->import();
    $migration
      ->getIdMap()
      ->prepareUpdate();
    foreach ($expected[$i] as $data) {
      $entity = $storage
        ->loadRevision($data['revision_id']);
      $this
        ->assertEquals($data['label'], $entity
        ->label());
      $this
        ->assertEquals($data['id'], $entity
        ->id());
    }
  }
  $migrationExecutable
    ->rollback();
  for ($i = 0; $i < 2; $i++) {
    foreach ($expected[$i] as $data) {
      $entity = $storage
        ->loadRevision($data['id']);
      $this
        ->assertEmpty($entity);
    }
  }
}