Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / SubProcessTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit\process;
4
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;
10
11 /**
12  * Tests the sub_process process plugin.
13  *
14  * @group migrate
15  */
16 class SubProcessTest extends MigrateTestCase {
17
18   /**
19    * The sub_process plugin being tested.
20    *
21    * @var \Drupal\migrate\Plugin\migrate\process\SubProcess
22    */
23   protected $plugin;
24
25   /**
26    * @var array
27    */
28   protected $migrationConfiguration = [
29     'id' => 'test',
30   ];
31
32   /**
33    * Tests the sub_process process plugin.
34    */
35   public function testSubProcess() {
36     $migration = $this->getMigration();
37     // Set up the properties for the sub_process.
38     $configuration = [
39       'process' => [
40         'foo' => 'source_foo',
41         'id' => 'source_id',
42       ],
43       'key' => '@id',
44     ];
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', []);
50     }
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);
61
62     // The current value of the pipeline.
63     $current_value = [
64       [
65         'source_foo' => 'test',
66         'source_id' => 42,
67       ],
68     ];
69     // This is not used but the interface requires it, so create an empty row.
70     $row = new Row();
71
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);
80   }
81
82 }