From 8a7ce9daf7f3fd7786ec8091902f295c1437aa4c Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Mon, 11 Jan 2021 22:11:02 +0000
Subject: [PATCH] Issue #3077322 by aleevas, quietone, RoSk0, mikelutz,
 Lendude: Add test for NULL source value to test of static_map process plugin

---
 .../tests/src/Unit/process/StaticMapTest.php  | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php
index c7f7129e95f3..6bb54286b738 100644
--- a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php
@@ -91,4 +91,24 @@ public function testMapWithInvalidSourceAndBypass() {
     $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destination_property');
   }
 
+  /**
+   * Tests when the source is NULL.
+   */
+  public function testWithNullSourceNotInMap() {
+    $this->expectException(MigrateSkipRowException::class);
+    $this->expectExceptionMessage("No static mapping found for 'NULL' and no default value provided for destination 'destination_property'");
+    $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destination_property');
+  }
+
+  /**
+   * Tests when the source is invalid but there's a default.
+   */
+  public function testWithNullSource() {
+    $configuration['map']['foo']['bar'] = 'baz';
+    $configuration['map'][NULL] = 'mapped NULL';
+    $this->plugin = new StaticMap($configuration, 'map', []);
+    $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destination_property');
+    $this->assertSame('mapped NULL', $value);
+  }
+
 }
-- 
GitLab