Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / ArrayBuildTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit\process;
4
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\Plugin\migrate\process\ArrayBuild;
7
8 /**
9  * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\ArrayBuild
10  * @group migrate
11  */
12 class ArrayBuildTest extends MigrateProcessTestCase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function setUp() {
18     $configuration = [
19       'key' => 'foo',
20       'value' => 'bar',
21     ];
22     $this->plugin = new ArrayBuild($configuration, 'map', []);
23     parent::setUp();
24   }
25
26   /**
27    * Tests successful transformation.
28    */
29   public function testTransform() {
30     $source = [
31       ['foo' => 'Foo', 'bar' => 'Bar'],
32       ['foo' => 'foo bar', 'bar' => 'bar foo'],
33     ];
34     $expected = [
35       'Foo' => 'Bar',
36       'foo bar' => 'bar foo',
37     ];
38     $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
39     $this->assertSame($value, $expected);
40   }
41
42   /**
43    * Tests non-existent key for the key configuration.
44    */
45   public function testNonExistentKey() {
46     $source = [
47       ['bar' => 'foo'],
48     ];
49     $this->setExpectedException(MigrateException::class, "The key 'foo' does not exist");
50     $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
51   }
52
53   /**
54    * Tests non-existent key for the value configuration.
55    */
56   public function testNonExistentValue() {
57     $source = [
58       ['foo' => 'bar'],
59     ];
60     $this->setExpectedException(MigrateException::class, "The key 'bar' does not exist");
61     $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
62   }
63
64   /**
65    * Tests one-dimensional array input.
66    */
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');
71   }
72
73   /**
74    * Tests string input.
75    */
76   public function testStringInput() {
77     $source = 'foo';
78     $this->setExpectedException(MigrateException::class, 'The input should be an array of arrays');
79     $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
80   }
81
82 }