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