function EntityRevisionTest::testGetEntityNewRevision

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php \Drupal\Tests\migrate\Unit\destination\EntityRevisionTest::testGetEntityNewRevision()
  2. 10 core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php \Drupal\Tests\migrate\Unit\destination\EntityRevisionTest::testGetEntityNewRevision()
  3. 11.x core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php \Drupal\Tests\migrate\Unit\destination\EntityRevisionTest::testGetEntityNewRevision()

Test that new revisions are flagged to be written as new.

@covers ::getEntity

File

core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php, line 112

Class

EntityRevisionTest
Tests entity revision destination.

Namespace

Drupal\Tests\migrate\Unit\destination

Code

public function testGetEntityNewRevision() {
    $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());
    // Enforce is new should be disabled.
    $entity->enforceIsNew(FALSE)
        ->shouldBeCalled();
    // And toggle this as new revision but not the default revision.
    $entity->setNewRevision(TRUE)
        ->shouldBeCalled();
    $entity->isDefaultRevision(FALSE)
        ->shouldBeCalled();
    // Assert we load the correct revision.
    $this->storage
        ->load(1)
        ->shouldBeCalled()
        ->willReturn($entity->reveal());
    $row = new Row([
        'nid' => 1,
        'vid' => 2,
    ], [
        'nid' => 1,
        'vid' => 2,
    ]);
    $row->setDestinationProperty('nid', 1);
    $this->assertEquals($entity->reveal(), $destination->getEntity($row, []));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.