Skip to content
Snippets Groups Projects
Commit 3b62ac71 authored by catch's avatar catch
Browse files

Issue #2827656 by maxocub, aditya.n: Once a process plugin returns multiple...

Issue #2827656 by maxocub, aditya.n: Once a process plugin returns multiple values, all following plugins are expected to handle multiple values
parent 729340a8
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -398,7 +398,7 @@ public function processRow(Row $row, array $process = NULL, $value = NULL) {
$value = NULL;
break;
}
$multiple = $multiple || $plugin->multiple();
$multiple = $plugin->multiple();
}
}
// No plugins or no value means do not set.
......
<?php
namespace Drupal\Tests\migrate\Kernel\process;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\Plugin\MigrationInterface;
/**
* Tests process pipelines with scalar and multiple values handling.
*
* @group migrate
*/
class HandleMultiplesTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['migrate'];
/**
* Provides the test migration definition.
*
* @return array
*/
public function getDefinition() {
return [
'source' => [
'plugin' => 'embedded_data',
'data_rows' => [],
'ids' => [
'id' => ['type' => 'string'],
],
],
'process' => [
// Process pipeline for testing values from string to array to string.
'first' => [
// Expects a string and returns an array.
[
'plugin' => 'explode',
'source' => 'scalar',
'delimiter' => '/',
],
// Expects an array and returns a string.
[
'plugin' => 'extract',
'index' => [1],
],
// Expects a string and returns a string.
[
'plugin' => 'callback',
'callable' => 'strtoupper',
],
],
// Process pipeline for testing values from array to string to array.
'second' => [
// Expects an array and returns a string.
[
'plugin' => 'extract',
'source' => 'multiple',
'index' => [1],
],
// Expects a string and returns a string.
[
'plugin' => 'callback',
'callable' => 'strtoupper',
],
// Expects a string and returns an array.
[
'plugin' => 'explode',
'delimiter' => '/',
],
],
],
'destination' => [
'plugin' => 'config',
'config_name' => 'migrate_test.settings',
],
];
}
/**
* Tests process pipelines with scalar and multiple values handling.
*
* @dataProvider scalarAndMultipleValuesProviderSource
*
* @param array $source_data
* @param array $expected_data
*/
public function testScalarAndMultipleValues(array $source_data, array $expected_data) {
$definition = $this->getDefinition();
$definition['source']['data_rows'] = [$source_data];
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$result = $executable->import();
// Migration needs to succeed before further assertions are made.
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $result);
// Compare with expected data.
$this->assertEquals($expected_data, \Drupal::config('migrate_test.settings')->get());
}
/**
* Provides the source data with scalar and multiple values.
*
* @return array
*/
public function scalarAndMultipleValuesProviderSource() {
return [
[
'source_data' => [
'id' => '1',
// Source value for the first pipeline.
'scalar' => 'foo/bar',
// Source value for the second pipeline.
'multiple' => [
'foo',
'bar/baz',
],
],
'expected_data' => [
// Expected value from the first pipeline.
'first' => 'BAR',
// Expected value from the second pipeline.
'second' => [
'BAR',
'BAZ',
],
],
],
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment