ConcatTest.php 1.53 KB
Newer Older
1 2 3 4
<?php

/**
 * @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 12 13
use Drupal\migrate\Plugin\migrate\process\Concat;

/**
14 15
 * Tests the concat process plugin.
 *
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 * @group migrate
 */
class ConcatTest extends MigrateProcessTestCase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    $this->plugin = new TestConcat();
    parent::setUp();
  }

  /**
   * Test concat works without a delimiter.
   */
  public function testConcatWithoutDelimiter() {
32
    $value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destination_property');
33
    $this->assertSame('foobar', $value);
34 35 36 37 38 39
  }

  /**
   * Test concat fails properly on non-arrays.
   */
  public function testConcatWithNonArray() {
40
    $this->expectException(MigrateException::class);
41
    $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destination_property');
42 43 44 45 46 47 48
  }

  /**
   * Test concat works without a delimiter.
   */
  public function testConcatWithDelimiter() {
    $this->plugin->setDelimiter('_');
49
    $value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destination_property');
50
    $this->assertSame('foo_bar', $value);
51
  }
52

53 54 55
}

class TestConcat extends Concat {
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70
  public function __construct() {
  }

  /**
   * Set the delimiter.
   *
   * @param string $delimiter
   *   The new delimiter.
   */
  public function setDelimiter($delimiter) {
    $this->configuration['delimiter'] = $delimiter;
  }

}