/** * Get the source plugin to test. * * @param array $configuration * The source configuration. * @param array $migrate_config * The migration configuration to be used in parent::getMigration(). * @param int $status * The default status for the new rows to be imported. * * @return \Drupal\migrate\Plugin\MigrateSourceInterface * A mocked source plugin. */ 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(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->migration = $this->getMigration(); $this->message = $this->getMock('Drupal\\migrate\\MigrateMessageInterface'); $event_dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->executable = new TestMigrateExecutable($this->migration, $this->message, $event_dispatcher); $this->executable->setStringTranslation($this->getStringTranslationStub()); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->migration = $this->getMigration(); $this->message = $this->getMock('Drupal\\migrate\\MigrateMessageInterface'); $this->executable = new TestMigrateExecutable($this->migration, $this->message); $this->executable->setStringTranslation($this->getStringTranslationStub()); $this->executable->setTimeThreshold(0.1); $this->executable->limit = array('unit' => 'second', 'value' => 1); }
/** * Gets the source plugin to test. * * @param array $configuration * (optional) The source configuration. Defaults to an empty array. * @param array $migrate_config * (optional) The migration configuration to be used in * parent::getMigration(). Defaults to an empty array. * @param int $status * (optional) The default status for the new rows to be imported. Defaults * to MigrateIdMapInterface::STATUS_NEEDS_UPDATE. * * @return \Drupal\migrate\Plugin\MigrateSourceInterface * A mocked source plugin. */ protected function getSource($configuration = [], $migrate_config = [], $status = MigrateIdMapInterface::STATUS_NEEDS_UPDATE, $high_water_value = NULL) { $container = new ContainerBuilder(); \Drupal::setContainer($container); $key_value = $this->getMock(KeyValueStoreInterface::class); $key_value_factory = $this->getMock(KeyValueFactoryInterface::class); $key_value_factory->method('get')->with('migrate:high_water')->willReturn($key_value); $container->set('keyvalue', $key_value_factory); $container->set('cache.migrate', $this->getMock(CacheBackendInterface::class)); $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', 'prepareRow', 'initializeIterator']; $source_plugin = $this->getMock(SourcePluginBase::class, $methods, $constructor_args); $source_plugin->method('fields')->willReturn([]); $source_plugin->method('getIds')->willReturn([]); $source_plugin->method('__toString')->willReturn(''); $source_plugin->method('prepareRow')->willReturn(empty($migrate_config['prepare_row_false'])); $rows = [$this->row]; if (isset($configuration['high_water_property']) && isset($high_water_value)) { $property = $configuration['high_water_property']['name']; $rows = array_filter($rows, function (array $row) use($property, $high_water_value) { return $row[$property] >= $high_water_value; }); } $iterator = new \ArrayIterator($rows); $source_plugin->method('initializeIterator')->willReturn($iterator); $module_handler = $this->getMock(ModuleHandlerInterface::class); $source_plugin->method('getModuleHandler')->willReturn($module_handler); $this->migration->method('getSourcePlugin')->willReturn($source_plugin); return $source_plugin; }
/** * {@inheritdoc} */ protected function setUp() { $this->row = $this->getMockBuilder('Drupal\\migrate\\Row')->disableOriginalConstructor()->getMock(); $this->migrateExecutable = $this->getMockBuilder('Drupal\\migrate\\MigrateExecutable')->disableOriginalConstructor()->getMock(); parent::setUp(); }
/** * {@inheritdoc} */ protected function setUp() { $this->migration = $this->getMigration(); parent::setUp(); }