ConcatTest.php

Same filename in other branches
  1. 9 core/modules/migrate/tests/src/Unit/process/ConcatTest.php
  2. 10 core/modules/migrate/tests/src/Unit/process/ConcatTest.php
  3. 11.x core/modules/migrate/tests/src/Unit/process/ConcatTest.php

Contains \Drupal\Tests\migrate\Unit\process\ConcatTest.

Namespace

Drupal\Tests\migrate\Unit\process

File

core/modules/migrate/tests/src/Unit/process/ConcatTest.php

View source
<?php


/**
 * @file
 * Contains \Drupal\Tests\migrate\Unit\process\ConcatTest.
 */
namespace Drupal\Tests\migrate\Unit\process;

use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\process\Concat;

/**
 * Tests the concat process plugin.
 *
 * @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() {
        $value = $this->plugin
            ->transform([
            'foo',
            'bar',
        ], $this->migrateExecutable, $this->row, 'destination_property');
        $this->assertSame('foobar', $value);
    }
    
    /**
     * Test concat fails properly on non-arrays.
     */
    public function testConcatWithNonArray() {
        $this->expectException(MigrateException::class);
        $this->plugin
            ->transform('foo', $this->migrateExecutable, $this->row, 'destination_property');
    }
    
    /**
     * Test concat works without a delimiter.
     */
    public function testConcatWithDelimiter() {
        $this->plugin
            ->setDelimiter('_');
        $value = $this->plugin
            ->transform([
            'foo',
            'bar',
        ], $this->migrateExecutable, $this->row, 'destination_property');
        $this->assertSame('foo_bar', $value);
    }

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

}

Classes

Title Deprecated Summary
ConcatTest Tests the concat process plugin.
TestConcat

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.