From 5cd98e7bc889e994ef3747ff0c6b88006cb153c6 Mon Sep 17 00:00:00 2001
From: Matroskeen <matroskeen@3426249.no-reply.drupal.org>
Date: Fri, 18 Mar 2022 12:00:01 +0000
Subject: [PATCH] Issue: #3269494: Add a test for config entity lookup.

---
 .../migrate/process/EntityLookupTest.php      | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php b/tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php
index b47ef8b7..f5cf2011 100644
--- a/tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php
+++ b/tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php
@@ -21,6 +21,13 @@ final class EntityLookupTest extends KernelTestBase {
 
   use UserCreationTrait;
 
+  /**
+   * The migrate executable mock object.
+   *
+   * @var \Drupal\migrate\MigrateExecutable|\PHPUnit\Framework\MockObject\MockObject
+   */
+  protected $migrateExecutable;
+
   /**
    * {@inheritdoc}
    */
@@ -29,6 +36,7 @@ final class EntityLookupTest extends KernelTestBase {
     'migrate',
     'user',
     'system',
+    'filter',
   ];
 
   /**
@@ -38,6 +46,11 @@ final class EntityLookupTest extends KernelTestBase {
     parent::setUp();
     $this->installSchema('system', ['sequences']);
     $this->installEntitySchema('user');
+    $this->installConfig(['filter']);
+
+    $this->migrateExecutable = $this->getMockBuilder('Drupal\migrate\MigrateExecutable')
+      ->disableOriginalConstructor()
+      ->getMock();
   }
 
   /**
@@ -75,4 +88,29 @@ final class EntityLookupTest extends KernelTestBase {
     $this->assertNull($value);
   }
 
+  /**
+   * Tests a lookup of config entity.
+   */
+  public function testConfigEntityLookup(): void {
+    $migration = \Drupal::service('plugin.manager.migration')
+      ->createStubMigration([
+        'id' => 'test',
+        'source' => [],
+        'process' => [],
+        'destination' => [
+          'plugin' => 'entity:node',
+        ],
+      ]);
+
+    $configuration = [
+      'entity_type' => 'filter_format',
+      'value_key' => 'name',
+    ];
+
+    $plugin = \Drupal::service('plugin.manager.migrate.process')
+      ->createInstance('entity_lookup', $configuration, $migration);
+    $value = $plugin->transform('Plain text', $this->migrateExecutable, new Row(), 'destination_property');
+    $this->assertEquals('plain_text', $value);
+  }
+
 }
-- 
GitLab