3 namespace Drupal\Tests\migrate\Unit\process;
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\Plugin\migrate\process\ArrayBuild;
9 * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\ArrayBuild
12 class ArrayBuildTest extends MigrateProcessTestCase {
17 protected function setUp() {
22 $this->plugin = new ArrayBuild($configuration, 'map', []);
27 * Tests successful transformation.
29 public function testTransform() {
31 ['foo' => 'Foo', 'bar' => 'Bar'],
32 ['foo' => 'foo bar', 'bar' => 'bar foo'],
36 'foo bar' => 'bar foo',
38 $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
39 $this->assertSame($value, $expected);
43 * Tests non-existent key for the key configuration.
45 public function testNonExistentKey() {
49 $this->setExpectedException(MigrateException::class, "The key 'foo' does not exist");
50 $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
54 * Tests non-existent key for the value configuration.
56 public function testNonExistentValue() {
60 $this->setExpectedException(MigrateException::class, "The key 'bar' does not exist");
61 $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
65 * Tests one-dimensional array input.
67 public function testOneDimensionalArrayInput() {
68 $source = ['foo' => 'bar'];
69 $this->setExpectedException(MigrateException::class, 'The input should be an array of arrays');
70 $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
76 public function testStringInput() {
78 $this->setExpectedException(MigrateException::class, 'The input should be an array of arrays');
79 $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');