You are here

protected function MigrateSourceTest::getSource 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::getSource()

Get the source plugin to test.

Parameters

array $configuration: The source configuration.

array $migrate_config: The migration configuration to be used in parent::getMigration().

int $status: The default status for the new rows to be imported.

Return value

\Drupal\migrate\Plugin\MigrateSourceInterface A mocked source plugin.

6 calls to MigrateSourceTest::getSource()
MigrateSourceTest::testCount in core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
Test that the source count is correct.
MigrateSourceTest::testHighwaterTrackChangesIncompatible in core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
@covers ::__construct @expectedException \Drupal\migrate\MigrateException
MigrateSourceTest::testNewHighwater in core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
Test that a highwater mark newer than our saved one imports a row.
MigrateSourceTest::testNextNeedsUpdate in core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
Test that $row->needsUpdate() works as expected.
MigrateSourceTest::testOutdatedHighwater in core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
Test that an outdated highwater mark does not cause a row to be imported.

... See full list

File

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

Class

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

Namespace

Drupal\Tests\migrate\Unit

Code

protected function getSource($configuration = [], $migrate_config = [], $status = MigrateIdMapInterface::STATUS_NEEDS_UPDATE) {
  $this->migrationConfiguration = $this->defaultMigrationConfiguration + $migrate_config;
  $this->migration = parent::getMigration();
  $this->executable = $this
    ->getMigrateExecutable($this->migration);

  // Update the idMap for Source so the default is that the row has already
  // been imported. This allows us to use the highwater mark to decide on the
  // outcome of whether we choose to import the row.
  $id_map_array = [
    'original_hash' => '',
    'hash' => '',
    'source_row_status' => $status,
  ];
  $this->idMap
    ->expects($this
    ->any())
    ->method('getRowBySource')
    ->willReturn($id_map_array);
  $constructor_args = [
    $configuration,
    'd6_action',
    [],
    $this->migration,
  ];
  $methods = [
    'getModuleHandler',
    'fields',
    'getIds',
    '__toString',
    'getIterator',
    'prepareRow',
    'initializeIterator',
    'calculateDependencies',
  ];
  $source_plugin = $this
    ->getMock('\\Drupal\\migrate\\Plugin\\migrate\\source\\SourcePluginBase', $methods, $constructor_args);
  $source_plugin
    ->expects($this
    ->any())
    ->method('fields')
    ->willReturn([]);
  $source_plugin
    ->expects($this
    ->any())
    ->method('getIds')
    ->willReturn([]);
  $source_plugin
    ->expects($this
    ->any())
    ->method('__toString')
    ->willReturn('');
  $source_plugin
    ->expects($this
    ->any())
    ->method('prepareRow')
    ->willReturn(empty($migrate_config['prepare_row_false']));
  $source_plugin
    ->expects($this
    ->any())
    ->method('initializeIterator')
    ->willReturn([]);
  $iterator = new \ArrayIterator([
    $this->row,
  ]);
  $source_plugin
    ->expects($this
    ->any())
    ->method('getIterator')
    ->willReturn($iterator);
  $module_handler = $this
    ->getMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
  $source_plugin
    ->expects($this
    ->any())
    ->method('getModuleHandler')
    ->willReturn($module_handler);
  $this->migration
    ->expects($this
    ->any())
    ->method('getSourcePlugin')
    ->willReturn($source_plugin);
  return $this->migration
    ->getSourcePlugin();
}