You are here

public function EntityReferenceRevisionsDestinationTest::testGetEntity in Entity Reference Revisions 8

Tests get entity.

@dataProvider getEntityDataProvider

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

File

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

Class

EntityReferenceRevisionsDestinationTest
Tests the migration destination plugin.

Namespace

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

Code

public function testGetEntity(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 as $data) {
      $entity = $storage
        ->loadRevision($data['revision_id']);
      $this
        ->assertEquals($data['label'], $entity
        ->label());
      $this
        ->assertEquals($data['id'], $entity
        ->id());
    }
  }
  $migrationExecutable
    ->rollback();
  foreach ($expected as $data) {
    $entity = $storage
      ->loadRevision($data['id']);
    $this
      ->assertEmpty($entity);
  }
}