Skip to content
Snippets Groups Projects
Commit afb2a792 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2684575 by chx, benjy, quietone: Get is unable to pick up 0

parent 0f0c2c3e
No related branches found
No related tags found
No related merge requests found
......@@ -35,10 +35,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$properties = is_string($source) ? array($source) : $source;
$return = array();
foreach ($properties as $property) {
if (empty($property)) {
$return[] = $value;
}
else {
if ($property || (string) $property === '0') {
$is_source = TRUE;
if ($property[0] == '@') {
$property = preg_replace_callback('/^(@?)((?:@@)*)([^@]|$)/', function ($matches) use (&$is_source) {
......@@ -57,7 +54,11 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$return[] = $row->getDestinationProperty($property);
}
}
else {
$return[] = $value;
}
}
if (is_string($source)) {
$this->multiple = is_array($return[0]);
return $return[0];
......
......@@ -82,6 +82,28 @@ public function testTransformSourceArrayAt() {
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame($value, array('source_value1', 'source_value2', 'source_value3', 'source_value4'));
}
/**
* Tests the Get plugin when source has integer values.
*/
public function testIntegerValues() {
$this->row->expects($this->exactly(2))
->method('getSourceProperty')
->willReturnOnConsecutiveCalls('val1', 'val2');
$this->plugin->setSource([0 => 0, 1 => 'test']);
$return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame([0 => 'val1', 1 => 'val2'], $return);
$this->plugin->setSource([FALSE]);
$return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame([NULL], $return);
$this->plugin->setSource([NULL]);
$return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame([NULL], $return);
}
}
namespace Drupal\migrate\Plugin\migrate\process;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment