You are here

public function MigrateExecutableTest::testImportWithValidRowWithoutDestinationId in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testImportWithValidRowWithoutDestinationId()
  2. 10 core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testImportWithValidRowWithoutDestinationId()

Tests the import method with a valid row.

File

core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php, line 132

Class

MigrateExecutableTest
@coversDefaultClass \Drupal\migrate\MigrateExecutable @group migrate

Namespace

Drupal\Tests\migrate\Unit

Code

public function testImportWithValidRowWithoutDestinationId() {
  $source = $this
    ->getMockSource();
  $row = $this
    ->getMockBuilder('Drupal\\migrate\\Row')
    ->disableOriginalConstructor()
    ->getMock();
  $row
    ->expects($this
    ->once())
    ->method('getSourceIdValues')
    ->will($this
    ->returnValue([
    'id' => 'test',
  ]));
  $this->idMap
    ->expects($this
    ->once())
    ->method('lookupDestinationIds')
    ->with([
    'id' => 'test',
  ])
    ->will($this
    ->returnValue([
    [
      'test',
    ],
  ]));
  $source
    ->expects($this
    ->once())
    ->method('current')
    ->will($this
    ->returnValue($row));
  $this->executable
    ->setSource($source);
  $this->migration
    ->expects($this
    ->once())
    ->method('getProcessPlugins')
    ->will($this
    ->returnValue([]));
  $destination = $this
    ->createMock('Drupal\\migrate\\Plugin\\MigrateDestinationInterface');
  $destination
    ->expects($this
    ->once())
    ->method('import')
    ->with($row, [
    'test',
  ])
    ->will($this
    ->returnValue(TRUE));
  $this->migration
    ->method('getDestinationPlugin')
    ->willReturn($destination);
  $this->idMap
    ->expects($this
    ->never())
    ->method('saveIdMapping');
  $this
    ->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable
    ->import());
}