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($value, 'source_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) { return $map[$argument]; } ));
52 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
53 $this->assertSame($value, ['source_value1', 'source_value2']);
57 * Tests the Get plugin when source is a string pointing to destination.
59 public function testTransformSourceStringAt() {
60 $this->row->expects($this->once())
61 ->method('getSourceProperty')
63 ->will($this->returnValue('source_value'));
64 $this->plugin->setSource('@@test');
65 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
66 $this->assertSame($value, 'source_value');
70 * Tests the Get plugin when source is an array pointing to destination.
72 public function testTransformSourceArrayAt() {
74 'test1' => 'source_value1',
75 '@test2' => 'source_value2',
76 '@test3' => 'source_value3',
77 'test4' => 'source_value4',
79 $this->plugin->setSource(['test1', '@@test2', '@@test3', 'test4']);
80 $this->row->expects($this->exactly(4))
81 ->method('getSourceProperty')
82 ->will($this->returnCallback(function ($argument) use ($map) { return $map[$argument]; } ));
83 $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
84 $this->assertSame($value, ['source_value1', 'source_value2', 'source_value3', 'source_value4']);
88 * Tests the Get plugin when source has integer values.
90 public function testIntegerValues() {
91 $this->row->expects($this->exactly(2))
92 ->method('getSourceProperty')
93 ->willReturnOnConsecutiveCalls('val1', 'val2');
95 $this->plugin->setSource([0 => 0, 1 => 'test']);
96 $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
97 $this->assertSame([0 => 'val1', 1 => 'val2'], $return);
99 $this->plugin->setSource([FALSE]);
100 $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
101 $this->assertSame([NULL], $return);
103 $this->plugin->setSource([NULL]);
104 $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
105 $this->assertSame([NULL], $return);
110 namespace Drupal\migrate\Plugin\migrate\process;
112 class TestGet extends Get {
113 public function __construct() {
115 public function setSource($source) {
116 $this->configuration['source'] = $source;