You are here

public function EntityContentBaseTest::testImport in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php \Drupal\Tests\migrate\Unit\Plugin\migrate\destination\EntityContentBaseTest::testImport()

Tests basic entity save.

@covers ::import

File

core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php, line 30
Contains \Drupal\Tests\migrate\Unit\Plugin\migrate\destination\EntityContentBaseTest.

Class

EntityContentBaseTest
Tests base entity migration destination functionality.

Namespace

Drupal\Tests\migrate\Unit\Plugin\migrate\destination

Code

public function testImport() {
  $bundles = [];
  $destination = new EntityTestDestination([], '', [], $this->migration
    ->reveal(), $this->storage
    ->reveal(), $bundles, $this->entityFieldManager
    ->reveal(), $this
    ->prophesize(FieldTypePluginManagerInterface::class)
    ->reveal());
  $entity = $this
    ->prophesize(ContentEntityInterface::class);
  $entity
    ->isValidationRequired()
    ->shouldBeCalledTimes(1);

  // Assert that save is called.
  $entity
    ->save()
    ->shouldBeCalledTimes(1);

  // Set an id for the entity
  $entity
    ->id()
    ->willReturn(5);
  $destination
    ->setEntity($entity
    ->reveal());

  // Ensure the id is saved entity id is returned from import.
  $this
    ->assertEquals([
    5,
  ], $destination
    ->import(new Row()));

  // Assert that import set the rollback action.
  $this
    ->assertEquals(MigrateIdMapInterface::ROLLBACK_DELETE, $destination
    ->rollbackAction());
}