View source
<?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\migrate\Plugin\migrate\process\StaticMap;
class StaticMapTest extends MigrateProcessTestCase {
protected function setUp() {
$configuration['map']['foo']['bar'] = 'baz';
$this->plugin = new StaticMap($configuration, 'map', array());
parent::setUp();
}
public function testMapWithSourceString() {
$value = $this->plugin
->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertSame($value, array(
'bar' => 'baz',
));
}
public function testMapWithSourceList() {
$value = $this->plugin
->transform(array(
'foo',
'bar',
), $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertSame($value, 'baz');
}
public function testMapwithEmptySource() {
$this->plugin
->transform(array(), $this->migrateExecutable, $this->row, 'destinationproperty');
}
public function testMapwithInvalidSource() {
$this->plugin
->transform(array(
'bar',
), $this->migrateExecutable, $this->row, 'destinationproperty');
}
public function testMapWithInvalidSourceWithADefaultValue() {
$configuration['map']['foo']['bar'] = 'baz';
$configuration['default_value'] = 'test';
$this->plugin = new StaticMap($configuration, 'map', array());
$value = $this->plugin
->transform(array(
'bar',
), $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertSame($value, 'test');
}
public function testMapWithInvalidSourceAndBypass() {
$configuration['map']['foo']['bar'] = 'baz';
$configuration['default_value'] = 'test';
$configuration['bypass'] = TRUE;
$this->plugin = new StaticMap($configuration, 'map', array());
$this->plugin
->transform(array(
'bar',
), $this->migrateExecutable, $this->row, 'destinationproperty');
}
}