You are here

public function MigrateSourceTest::testPrepareRow in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/tests/src/Unit/MigrateSourceTest.php \Drupal\Tests\migrate\Unit\MigrateSourceTest::testPrepareRow()

Test basic row preparation.

@covers ::prepareRow

File

core/modules/migrate/tests/src/Unit/MigrateSourceTest.php, line 236
Contains \Drupal\Tests\migrate\Unit\MigrateSourceTest.

Class

MigrateSourceTest
@coversDefaultClass \Drupal\migrate\Plugin\migrate\source\SourcePluginBase @group migrate

Namespace

Drupal\Tests\migrate\Unit

Code

public function testPrepareRow() {
  $this->migrationConfiguration['id'] = 'test_migration';

  // Get a new migration with an id.
  $migration = $this
    ->getMigration();
  $source = new StubSourcePlugin([], '', [], $migration);
  $row = new Row([], []);
  $module_handler = $this
    ->prophesize(ModuleHandlerInterface::class);
  $module_handler
    ->invokeAll('migrate_prepare_row', [
    $row,
    $source,
    $migration,
  ])
    ->willReturn([
    TRUE,
    TRUE,
  ])
    ->shouldBeCalled();
  $module_handler
    ->invokeAll('migrate_' . $migration
    ->id() . '_prepare_row', [
    $row,
    $source,
    $migration,
  ])
    ->willReturn([
    TRUE,
    TRUE,
  ])
    ->shouldBeCalled();
  $source
    ->setModuleHandler($module_handler
    ->reveal());

  // Ensure we don't log this to the mapping table.
  $this->idMap
    ->expects($this
    ->never())
    ->method('saveIdMapping');
  $this
    ->assertTrue($source
    ->prepareRow($row));

  // Track_changes...
  $source = new StubSourcePlugin([
    'track_changes' => TRUE,
  ], '', [], $migration);
  $row2 = $this
    ->prophesize(Row::class);
  $row2
    ->rehash()
    ->shouldBeCalled();
  $module_handler
    ->invokeAll('migrate_prepare_row', [
    $row2,
    $source,
    $migration,
  ])
    ->willReturn([
    TRUE,
    TRUE,
  ])
    ->shouldBeCalled();
  $module_handler
    ->invokeAll('migrate_' . $migration
    ->id() . '_prepare_row', [
    $row2,
    $source,
    $migration,
  ])
    ->willReturn([
    TRUE,
    TRUE,
  ])
    ->shouldBeCalled();
  $source
    ->setModuleHandler($module_handler
    ->reveal());
  $this
    ->assertTrue($source
    ->prepareRow($row2
    ->reveal()));
}