View source
<?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\migrate\Plugin\migrate\process\TestGet;
class GetTest extends MigrateProcessTestCase {
protected function setUp() {
$this->plugin = new TestGet();
parent::setUp();
}
public function testTransformSourceString() {
$this->row
->expects($this
->once())
->method('getSourceProperty')
->with('test')
->will($this
->returnValue('source_value'));
$this->plugin
->setSource('test');
$value = $this->plugin
->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertSame($value, 'source_value');
}
public function testTransformSourceArray() {
$map = array(
'test1' => 'source_value1',
'test2' => 'source_value2',
);
$this->plugin
->setSource(array(
'test1',
'test2',
));
$this->row
->expects($this
->exactly(2))
->method('getSourceProperty')
->will($this
->returnCallback(function ($argument) use ($map) {
return $map[$argument];
}));
$value = $this->plugin
->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertSame($value, array(
'source_value1',
'source_value2',
));
}
public function testTransformSourceStringAt() {
$this->row
->expects($this
->once())
->method('getSourceProperty')
->with('@test')
->will($this
->returnValue('source_value'));
$this->plugin
->setSource('@@test');
$value = $this->plugin
->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertSame($value, 'source_value');
}
public function testTransformSourceArrayAt() {
$map = array(
'test1' => 'source_value1',
'@test2' => 'source_value2',
'@test3' => 'source_value3',
'test4' => 'source_value4',
);
$this->plugin
->setSource(array(
'test1',
'@@test2',
'@@test3',
'test4',
));
$this->row
->expects($this
->exactly(4))
->method('getSourceProperty')
->will($this
->returnCallback(function ($argument) use ($map) {
return $map[$argument];
}));
$value = $this->plugin
->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertSame($value, array(
'source_value1',
'source_value2',
'source_value3',
'source_value4',
));
}
}
namespace Drupal\migrate\Plugin\migrate\process;
class TestGet extends Get {
public function __construct() {
}
public function setSource($source) {
$this->configuration['source'] = $source;
}
}