View source
<?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\process\ArrayBuild;
class ArrayBuildTest extends MigrateProcessTestCase {
protected function setUp() : void {
$configuration = [
'key' => 'foo',
'value' => 'bar',
];
$this->plugin = new ArrayBuild($configuration, 'map', []);
parent::setUp();
}
public function testTransform() {
$source = [
[
'foo' => 'Foo',
'bar' => 'Bar',
],
[
'foo' => 'foo bar',
'bar' => 'bar foo',
],
];
$expected = [
'Foo' => 'Bar',
'foo bar' => 'bar foo',
];
$value = $this->plugin
->transform($source, $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame($value, $expected);
}
public function testNonExistentKey() {
$source = [
[
'bar' => 'foo',
],
];
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage("The key 'foo' does not exist");
$this->plugin
->transform($source, $this->migrateExecutable, $this->row, 'destination_property');
}
public function testNonExistentValue() {
$source = [
[
'foo' => 'bar',
],
];
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage("The key 'bar' does not exist");
$this->plugin
->transform($source, $this->migrateExecutable, $this->row, 'destination_property');
}
public function testOneDimensionalArrayInput() {
$source = [
'foo' => 'bar',
];
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage('The input should be an array of arrays');
$this->plugin
->transform($source, $this->migrateExecutable, $this->row, 'destination_property');
}
public function testStringInput() {
$source = 'foo';
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage('The input should be an array of arrays');
$this->plugin
->transform($source, $this->migrateExecutable, $this->row, 'destination_property');
}
}