You are here

public function EntityRevisionTest::testGetEntityUpdateRevision in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php \Drupal\Tests\migrate\Unit\destination\EntityRevisionTest::testGetEntityUpdateRevision()

Test that revision updates update.

@covers ::getEntity

File

core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php, line 85
Contains \Drupal\Tests\migrate\Unit\destination\EntityRevisionTest.

Class

EntityRevisionTest
Tests entity revision destination.

Namespace

Drupal\Tests\migrate\Unit\destination

Code

public function testGetEntityUpdateRevision() {
  $destination = $this
    ->getEntityRevisionDestination([]);
  $entity = $this
    ->prophesize('\\Drupal\\Core\\Entity\\RevisionableInterface');
  $entity_type = $this
    ->prophesize('\\Drupal\\Core\\Entity\\EntityTypeInterface');
  $entity_type
    ->getKey('id')
    ->willReturn('nid');
  $entity_type
    ->getKey('revision')
    ->willReturn('vid');
  $this->storage
    ->getEntityType()
    ->willReturn($entity_type
    ->reveal());

  // Assert we load the correct revision.
  $this->storage
    ->loadRevision(2)
    ->shouldBeCalled()
    ->willReturn($entity
    ->reveal());

  // Make sure its set as an update and not the default revision.
  $entity
    ->setNewRevision(FALSE)
    ->shouldBeCalled();
  $entity
    ->isDefaultRevision(FALSE)
    ->shouldBeCalled();
  $row = new Row([
    'nid' => 1,
    'vid' => 2,
  ], [
    'nid' => 1,
    'vid' => 2,
  ]);
  $row
    ->setDestinationProperty('vid', 2);
  $this
    ->assertEquals($entity
    ->reveal(), $destination
    ->getEntity($row, []));
}