diff --git a/src/Plugin/migrate/process/ParseEntityLookup.php b/src/Plugin/migrate/process/ParseEntityLookup.php index 98a8eec..b148230 100644 --- a/src/Plugin/migrate/process/ParseEntityLookup.php +++ b/src/Plugin/migrate/process/ParseEntityLookup.php @@ -135,6 +135,10 @@ public static function create(ContainerInterface $container, array $configuratio } public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + if ($value == NULL || trim($value) == "") { + return NULL; + } + $delimiter = $this->configuration['delimiter'] ?: self::default_delimiter; // split the source value into fields using the defined delimiter diff --git a/tests/Plugin/migrate/process/ParseEntityLookupTest.php b/tests/Plugin/migrate/process/ParseEntityLookupTest.php index 130b4ff..939bcfa 100644 --- a/tests/Plugin/migrate/process/ParseEntityLookupTest.php +++ b/tests/Plugin/migrate/process/ParseEntityLookupTest.php @@ -352,6 +352,9 @@ public function testTransformOk() { self::assertTrue($transformInvoked); } + /** + * Improper formatting of the source value should result in a MigrateException + */ public function testTransformInvalidSourceValueTooSmall() { // The source value from the spreadsheet in the form: // ::: @@ -368,6 +371,9 @@ public function testTransformInvalidSourceValueTooSmall() { } } + /** + * Improper formatting of the source value should result in a MigrateException + */ public function testTransformInvalidSourceValueTooBig() { // The source value from the spreadsheet in the form: // ::: @@ -384,6 +390,9 @@ public function testTransformInvalidSourceValueTooBig() { } } + /** + * Improper formatting of the source value should result in a MigrateException + */ public function testTransformInvalidSourceValueEmptyLastElement() { // The source value from the spreadsheet in the form: // ::: @@ -399,4 +408,30 @@ public function testTransformInvalidSourceValueEmptyLastElement() { } } + /** + * Empty source values should result in NULL being returned. + */ + public function testEmptyValue() { + $source_value = " "; + $result = $this->underTest->transform($source_value, $this->mockMigrationExe, new Row(), "foo"); + self::assertNull($result); + } + + /** + * Zero-length source values should result in NULL being returned. + */ + public function testZeroLengthValue() { + $source_value = ""; + $result = $this->underTest->transform($source_value, $this->mockMigrationExe, new Row(), "foo"); + self::assertNull($result); + } + + /** + * NULL source values should result in NULL being returned. + */ + public function testNullValue() { + $source_value = NULL; + $result = $this->underTest->transform($source_value, $this->mockMigrationExe, new Row(), "foo"); + self::assertNull($result); + } } \ No newline at end of file