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\SubProcess;
8 use Drupal\migrate\Row;
9 use Drupal\Tests\migrate\Unit\MigrateTestCase;
12 * Tests the sub_process process plugin.
16 class SubProcessTest extends MigrateTestCase {
19 * The sub_process plugin being tested.
21 * @var \Drupal\migrate\Plugin\migrate\process\SubProcess
28 protected $migrationConfiguration = [
33 * Tests the sub_process process plugin.
35 public function testSubProcess() {
36 $migration = $this->getMigration();
37 // Set up the properties for the sub_process.
40 'foo' => 'source_foo',
45 $plugin = new SubProcess($configuration, 'sub_process', []);
46 // Manually create the plugins. Migration::getProcessPlugins does this
47 // normally but the plugin system is not available.
48 foreach ($configuration['process'] as $destination => $source) {
49 $sub_process_plugins[$destination][] = new Get(['source' => $source], 'get', []);
51 $migration->expects($this->at(1))
52 ->method('getProcessPlugins')
53 ->willReturn($sub_process_plugins);
54 // Set up the key plugins.
55 $key_plugin['key'][] = new Get(['source' => '@id'], 'get', []);
56 $migration->expects($this->at(2))
57 ->method('getProcessPlugins')
58 ->will($this->returnValue($key_plugin));
59 $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
60 $migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher);
62 // The current value of the pipeline.
65 'source_foo' => 'test',
69 // This is not used but the interface requires it, so create an empty row.
72 // After transformation, check to make sure that source_foo and source_id's
73 // values ended up in the proper destinations, and that the value of the
74 // key (@id) is the same as the destination ID (42).
75 $new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test');
76 $this->assertSame(count($new_value), 1);
77 $this->assertSame(count($new_value[42]), 2);
78 $this->assertSame($new_value[42]['foo'], 'test');
79 $this->assertSame($new_value[42]['id'], 42);