X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate%2Ftests%2Fsrc%2FUnit%2Fprocess%2FSubProcessTest.php;fp=web%2Fcore%2Fmodules%2Fmigrate%2Ftests%2Fsrc%2FUnit%2Fprocess%2FSubProcessTest.php;h=dfcdec3bc3648dc17124bd8e6e032aab482fba86;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php b/web/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php new file mode 100644 index 000000000..dfcdec3bc --- /dev/null +++ b/web/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php @@ -0,0 +1,82 @@ + 'test', + ]; + + /** + * Tests the sub_process process plugin. + */ + public function testSubProcess() { + $migration = $this->getMigration(); + // Set up the properties for the sub_process. + $configuration = [ + 'process' => [ + 'foo' => 'source_foo', + 'id' => 'source_id', + ], + 'key' => '@id', + ]; + $plugin = new SubProcess($configuration, 'sub_process', []); + // Manually create the plugins. Migration::getProcessPlugins does this + // normally but the plugin system is not available. + foreach ($configuration['process'] as $destination => $source) { + $sub_process_plugins[$destination][] = new Get(['source' => $source], 'get', []); + } + $migration->expects($this->at(1)) + ->method('getProcessPlugins') + ->willReturn($sub_process_plugins); + // Set up the key plugins. + $key_plugin['key'][] = new Get(['source' => '@id'], 'get', []); + $migration->expects($this->at(2)) + ->method('getProcessPlugins') + ->will($this->returnValue($key_plugin)); + $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher); + + // The current value of the pipeline. + $current_value = [ + [ + 'source_foo' => 'test', + 'source_id' => 42, + ], + ]; + // This is not used but the interface requires it, so create an empty row. + $row = new Row(); + + // After transformation, check to make sure that source_foo and source_id's + // values ended up in the proper destinations, and that the value of the + // key (@id) is the same as the destination ID (42). + $new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test'); + $this->assertSame(count($new_value), 1); + $this->assertSame(count($new_value[42]), 2); + $this->assertSame($new_value[42]['foo'], 'test'); + $this->assertSame($new_value[42]['id'], 42); + } + +}