Skip to content

Commit

Permalink
Merge pull request #7 from jhu-idc/null-values
Browse files Browse the repository at this point in the history
Properly handle NULL, empty, and zero-length values
  • Loading branch information
emetsger committed May 4, 2021
2 parents 73648cb + 12d90d9 commit 185ee10
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Plugin/migrate/process/ParseEntityLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions tests/Plugin/migrate/process/ParseEntityLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// <entity type>:<bundle>:<value_key>:<value>
Expand All @@ -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:
// <entity type>:<bundle>:<value_key>:<value>
Expand All @@ -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:
// <entity type>:<bundle>:<value_key>:<value>
Expand All @@ -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);
}
}

0 comments on commit 185ee10

Please sign in to comment.