3 namespace Drupal\Tests\migrate\Unit\process;
5 use Drupal\migrate\Plugin\migrate\process\Get;
8 * Tests the get process plugin.
12 class GetTest extends MigrateProcessTestCase {
15 * Tests the Get plugin when source is a string.
17 public function testTransformSourceString() {
18 $this->row->expects($this->once())
19 ->method('getSourceProperty')
21 ->will($this->returnValue('source_value'));
22 $this->plugin = new Get(['source' => 'test'], '', []);
23 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
24 $this->assertSame('source_value', $value);
28 * Tests the Get plugin when source is an array.
30 public function testTransformSourceArray() {
32 'test1' => 'source_value1',
33 'test2' => 'source_value2',
35 $this->plugin = new Get(['source' => ['test1', 'test2']], '', []);
36 $this->row->expects($this->exactly(2))
37 ->method('getSourceProperty')
38 ->will($this->returnCallback(function ($argument) use ($map) {
39 return $map[$argument];
41 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
42 $this->assertSame(['source_value1', 'source_value2'], $value);
46 * Tests the Get plugin when source is a string pointing to destination.
48 public function testTransformSourceStringAt() {
49 $this->row->expects($this->once())
50 ->method('getSourceProperty')
52 ->will($this->returnValue('source_value'));
53 $this->plugin = new Get(['source' => '@@test'], '', []);
54 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
55 $this->assertSame('source_value', $value);
59 * Tests the Get plugin when source is an array pointing to destination.
61 public function testTransformSourceArrayAt() {
63 'test1' => 'source_value1',
64 '@test2' => 'source_value2',
65 '@test3' => 'source_value3',
66 'test4' => 'source_value4',
68 $this->plugin = new Get(['source' => ['test1', '@@test2', '@@test3', 'test4']], '', []);
69 $this->row->expects($this->exactly(4))
70 ->method('getSourceProperty')
71 ->will($this->returnCallback(function ($argument) use ($map) {
72 return $map[$argument];
74 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
75 $this->assertSame(['source_value1', 'source_value2', 'source_value3', 'source_value4'], $value);
79 * Tests the Get plugin when source has integer values.
81 * @dataProvider integerValuesDataProvider
83 public function testIntegerValues($source, $expected_value) {
84 $this->row->expects($this->atMost(2))
85 ->method('getSourceProperty')
86 ->willReturnOnConsecutiveCalls('val1', 'val2');
88 $this->plugin = new Get(['source' => $source], '', []);
89 $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
90 $this->assertSame($expected_value, $return);
94 * Provides data for the successful lookup test.
98 public function integerValuesDataProvider() {
101 'source' => [0 => 0, 1 => 'test'],
102 'expected_value' => [0 => 'val1', 1 => 'val2'],
106 'expected_value' => [NULL],
110 'expected_value' => [NULL],
116 * Tests the Get plugin for syntax errors, e.g. "Invalid tag_line detected" by
117 * creating a prophecy of the class.
119 public function testPluginSyntax() {
120 $this->assertNotNull($this->prophesize(Get::class));