5 * Contains \Drupal\Tests\migrate\Unit\process\GetTest.
8 namespace Drupal\Tests\migrate\Unit\process;
10 use Drupal\migrate\Plugin\migrate\process\TestGet;
13 * Tests the get process plugin.
17 class GetTest extends MigrateProcessTestCase {
22 protected function setUp() {
23 $this->plugin = new TestGet();
28 * Tests the Get plugin when source is a string.
30 public function testTransformSourceString() {
31 $this->row->expects($this->once())
32 ->method('getSourceProperty')
34 ->will($this->returnValue('source_value'));
35 $this->plugin->setSource('test');
36 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
37 $this->assertSame('source_value', $value);
41 * Tests the Get plugin when source is an array.
43 public function testTransformSourceArray() {
45 'test1' => 'source_value1',
46 'test2' => 'source_value2',
48 $this->plugin->setSource(['test1', 'test2']);
49 $this->row->expects($this->exactly(2))
50 ->method('getSourceProperty')
51 ->will($this->returnCallback(function ($argument) use ($map) {
52 return $map[$argument];
54 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
55 $this->assertSame(['source_value1', 'source_value2'], $value);
59 * Tests the Get plugin when source is a string pointing to destination.
61 public function testTransformSourceStringAt() {
62 $this->row->expects($this->once())
63 ->method('getSourceProperty')
65 ->will($this->returnValue('source_value'));
66 $this->plugin->setSource('@@test');
67 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
68 $this->assertSame('source_value', $value);
72 * Tests the Get plugin when source is an array pointing to destination.
74 public function testTransformSourceArrayAt() {
76 'test1' => 'source_value1',
77 '@test2' => 'source_value2',
78 '@test3' => 'source_value3',
79 'test4' => 'source_value4',
81 $this->plugin->setSource(['test1', '@@test2', '@@test3', 'test4']);
82 $this->row->expects($this->exactly(4))
83 ->method('getSourceProperty')
84 ->will($this->returnCallback(function ($argument) use ($map) {
85 return $map[$argument];
87 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
88 $this->assertSame(['source_value1', 'source_value2', 'source_value3', 'source_value4'], $value);
92 * Tests the Get plugin when source has integer values.
94 public function testIntegerValues() {
95 $this->row->expects($this->exactly(2))
96 ->method('getSourceProperty')
97 ->willReturnOnConsecutiveCalls('val1', 'val2');
99 $this->plugin->setSource([0 => 0, 1 => 'test']);
100 $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
101 $this->assertSame([0 => 'val1', 1 => 'val2'], $return);
103 $this->plugin->setSource([FALSE]);
104 $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
105 $this->assertSame([NULL], $return);
107 $this->plugin->setSource([NULL]);
108 $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
109 $this->assertSame([NULL], $return);
114 namespace Drupal\migrate\Plugin\migrate\process;
116 class TestGet extends Get {
117 public function __construct() {
119 public function setSource($source) {
120 $this->configuration['source'] = $source;