IteratorTest.php in Drupal 8
File
core/modules/migrate/tests/src/Unit/process/IteratorTest.php
View source
<?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Plugin\migrate\process\Get;
use Drupal\migrate\Plugin\migrate\process\Iterator;
use Drupal\migrate\Row;
use Drupal\Tests\migrate\Unit\MigrateTestCase;
class IteratorTest extends MigrateTestCase {
protected $plugin;
protected $migrationConfiguration = [
'id' => 'test',
];
public function testIterator() {
$migration = $this
->getMigration();
$configuration = [
'process' => [
'foo' => 'source_foo',
'id' => 'source_id',
],
'key' => '@id',
];
$plugin = new Iterator($configuration, 'iterator', []);
foreach ($configuration['process'] as $destination => $source) {
$iterator_plugins[$destination][] = new Get([
'source' => $source,
], 'get', []);
}
$migration
->expects($this
->at(1))
->method('getProcessPlugins')
->will($this
->returnValue($iterator_plugins));
$key_plugin['key'][] = new Get([
'source' => '@id',
], 'get', []);
$migration
->expects($this
->at(2))
->method('getProcessPlugins')
->will($this
->returnValue($key_plugin));
$event_dispatcher = $this
->createMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$migrate_executable = new MigrateExecutable($migration, $this
->createMock('Drupal\\migrate\\MigrateMessageInterface'), $event_dispatcher);
$current_value = [
[
'source_foo' => 'test',
'source_id' => 42,
],
];
$row = new Row();
$new_value = $plugin
->transform($current_value, $migrate_executable, $row, 'test');
$this
->assertCount(1, $new_value);
$this
->assertCount(2, $new_value[42]);
$this
->assertSame('test', $new_value[42]['foo']);
$this
->assertSame(42, $new_value[42]['id']);
}
}