Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / ConcatTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Tests\migrate\Unit\process\ConcatTest.
6  */
7
8 namespace Drupal\Tests\migrate\Unit\process;
9
10 use Drupal\migrate\MigrateException;
11 use Drupal\migrate\Plugin\migrate\process\Concat;
12
13 /**
14  * Tests the concat process plugin.
15  *
16  * @group migrate
17  */
18 class ConcatTest extends MigrateProcessTestCase {
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     $this->plugin = new TestConcat();
25     parent::setUp();
26   }
27
28   /**
29    * Test concat works without a delimiter.
30    */
31   public function testConcatWithoutDelimiter() {
32     $value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
33     $this->assertSame('foobar', $value);
34   }
35
36   /**
37    * Test concat fails properly on non-arrays.
38    */
39   public function testConcatWithNonArray() {
40     $this->setExpectedException(MigrateException::class);
41     $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
42   }
43
44   /**
45    * Test concat works without a delimiter.
46    */
47   public function testConcatWithDelimiter() {
48     $this->plugin->setDelimiter('_');
49     $value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
50     $this->assertSame('foo_bar', $value);
51   }
52
53 }
54
55 class TestConcat extends Concat {
56   public function __construct() {
57   }
58
59   /**
60    * Set the delimiter.
61    *
62    * @param string $delimiter
63    *   The new delimiter.
64    */
65   public function setDelimiter($delimiter) {
66     $this->configuration['delimiter'] = $delimiter;
67   }
68
69 }