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\Iterator
28 protected $migrationConfiguration = [
33 * Tests the iterator process plugin.
36 * @expectedDeprecation The Drupal\migrate\Plugin\migrate\process\Iterator is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate\Plugin\migrate\process\SubProcess
38 public function testIterator() {
39 $migration = $this->getMigration();
40 // Set up the properties for the iterator.
43 'foo' => 'source_foo',
48 $plugin = new Iterator($configuration, 'iterator', []);
49 // Manually create the plugins. Migration::getProcessPlugins does this
50 // normally but the plugin system is not available.
51 foreach ($configuration['process'] as $destination => $source) {
52 $iterator_plugins[$destination][] = new Get(['source' => $source], 'get', []);
54 $migration->expects($this->at(1))
55 ->method('getProcessPlugins')
56 ->will($this->returnValue($iterator_plugins));
57 // Set up the key plugins.
58 $key_plugin['key'][] = new Get(['source' => '@id'], 'get', []);
59 $migration->expects($this->at(2))
60 ->method('getProcessPlugins')
61 ->will($this->returnValue($key_plugin));
62 $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
63 $migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher);
65 // The current value of the pipeline.
68 'source_foo' => 'test',
72 // This is not used but the interface requires it, so create an empty row.
75 // After transformation, check to make sure that source_foo and source_id's
76 // values ended up in the proper destinations, and that the value of the
77 // key (@id) is the same as the destination ID (42).
78 $new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test');
79 $this->assertSame(1, count($new_value));
80 $this->assertSame(2, count($new_value[42]));
81 $this->assertSame('test', $new_value[42]['foo']);
82 $this->assertSame(42, $new_value[42]['id']);