3 namespace Drupal\Tests\migrate\Unit\process;
5 use Drupal\migrate\MigrateExecutable;
6 use Drupal\migrate\Plugin\migrate\process\Get;
7 use Drupal\migrate\Plugin\migrate\process\Iterator;
8 use Drupal\migrate\Row;
9 use Drupal\Tests\migrate\Unit\MigrateTestCase;
12 * Tests the iterator process plugin.
16 class IteratorTest extends MigrateTestCase {
19 * The iterator plugin being tested.
21 * @var \Drupal\migrate\Plugin\migrate\process\TestIterator
28 protected $migrationConfiguration = [
33 * Tests the iterator process plugin.
37 public function testIterator() {
38 $migration = $this->getMigration();
39 // Set up the properties for the iterator.
42 'foo' => 'source_foo',
47 $plugin = new Iterator($configuration, 'iterator', []);
48 // Manually create the plugins. Migration::getProcessPlugins does this
49 // normally but the plugin system is not available.
50 foreach ($configuration['process'] as $destination => $source) {
51 $iterator_plugins[$destination][] = new Get(['source' => $source], 'get', []);
53 $migration->expects($this->at(1))
54 ->method('getProcessPlugins')
55 ->will($this->returnValue($iterator_plugins));
56 // Set up the key plugins.
57 $key_plugin['key'][] = new Get(['source' => '@id'], 'get', []);
58 $migration->expects($this->at(2))
59 ->method('getProcessPlugins')
60 ->will($this->returnValue($key_plugin));
61 $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
62 $migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher);
64 // The current value of the pipeline.
67 'source_foo' => 'test',
71 // This is not used but the interface requires it, so create an empty row.
74 // After transformation, check to make sure that source_foo and source_id's
75 // values ended up in the proper destinations, and that the value of the
76 // key (@id) is the same as the destination ID (42).
77 $new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test');
78 $this->assertSame(count($new_value), 1);
79 $this->assertSame(count($new_value[42]), 2);
80 $this->assertSame($new_value[42]['foo'], 'test');
81 $this->assertSame($new_value[42]['id'], 42);