diff --git a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php index ea93e46..8d037b0 100644 --- a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php @@ -1,10 +1,5 @@ plugin = new TestConcat(); - parent::setUp(); + public function testConcatWithoutDelimiter($input, $expected, $configuration = []) { + $this->plugin = new Concat($configuration, '', []); + $value = $this->plugin->transform($input, $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame($expected, $value); } /** - * Test concat works without a delimiter. + * Data provider for testConcatWithoutDelimiter(). */ - public function testConcatWithoutDelimiter() { - $value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame($value, 'foobar'); + public function providerConcatWithoutDelimiter() { + return [ + 'no configuration' => [['foo', 'bar'], 'foobar'], + 'with delimiter' => [['foo', 'bar'], 'foo_bar', ['delimiter' => '_']], + 'no delimiter, allow_empty is false' => [ + ['foo', NULL, 'bar'], + 'foobar', + ['allow_empty' => FALSE] + ], + 'no delimiter, allow_empty is true' => [ + ['foo', NULL, 'bar'], + 'foobar', + ['allow_empty' => TRUE] + ], + 'with delimiter, allow_empty is false, NULL' => [ + ['foo', NULL, 'bar'], + 'foo_bar', + ['delimiter' => '_', 'allow_empty' => FALSE] + ], + 'with delimiter, allow_empty is true, NULL' => [ + ['foo', NULL, 'bar'], + 'foo__bar', + ['delimiter' => '_', 'allow_empty' => TRUE] + ], + 'with delimiter, allow_empty is false, empty string' => [ + ['foo', '', 'bar'], + 'foo_bar', + ['delimiter' => '_', 'allow_empty' => FALSE] + ], + 'with delimiter, allow_empty is true, empty string' => [ + ['foo', '', 'bar'], + 'foo__bar', + ['delimiter' => '_', 'allow_empty' => TRUE] + ], + 'with delimiter, allow_empty is true, zero' => [ + ['foo', 0, 'bar'], + 'foo_0_bar', + ['delimiter' => '_', 'allow_empty' => TRUE] + ], + 'with delimiter, allow_empty is true, space' => [ + ['foo', ' ', 'bar'], + 'foo_ _bar', + ['delimiter' => '_', 'allow_empty' => TRUE] + ], + ]; } /** * Test concat fails properly on non-arrays. */ public function testConcatWithNonArray() { + $this->plugin = new Concat([], '', []); $this->setExpectedException(MigrateException::class); $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); } - /** - * Test concat works without a delimiter. - */ - public function testConcatWithDelimiter() { - $this->plugin->setDelimiter('_'); - $value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame($value, 'foo_bar'); - } - -} - -class TestConcat extends Concat { - public function __construct() { - } - - /** - * Set the delimiter. - * - * @param string $delimiter - * The new delimiter. - */ - public function setDelimiter($delimiter) { - $this->configuration['delimiter'] = $delimiter; - } - }