From ca621bc3d8fc07e5dfa516d091be85a015ca48a7 Mon Sep 17 00:00:00 2001 From: dinazaur <dinazaur@3637512.no-reply.drupal.org> Date: Sat, 29 Jan 2022 14:42:17 +0200 Subject: [PATCH] Issue #3261274: Throw consistent exceptions on \Drupal\migrate_plus\Plugin\migrate\process\EntityValue process plugin --- src/Plugin/migrate/process/EntityValue.php | 2 +- .../migrate/process/EntityValueTest.php | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Plugin/migrate/process/EntityValue.php b/src/Plugin/migrate/process/EntityValue.php index 77a7358c..75891b1a 100644 --- a/src/Plugin/migrate/process/EntityValue.php +++ b/src/Plugin/migrate/process/EntityValue.php @@ -151,7 +151,7 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt } else { if ($langcode) { - throw new \InvalidArgumentException('Langcode can only be used with content entities currently.'); + throw new MigrateException('Langcode can only be used with content entities currently.'); } } try { diff --git a/tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php b/tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php index e1e0962d..9ffe6657 100644 --- a/tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php +++ b/tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php @@ -3,10 +3,12 @@ namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; use Drupal\KernelTests\KernelTestBase; +use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; use Drupal\node\Entity\Node; use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\node\Entity\NodeType; /** * Tests the entity_value plugin. @@ -150,6 +152,31 @@ class EntityValueTest extends KernelTestBase { $this->assertTrue($this->plugin->multiple()); } + /** + * Test the EntityLoad plugin failure. + * + * @covers ::transform + */ + public function testEntityValueLangException() { + $config_entity = NodeType::create(['type' => 'page', 'name' => 'page']); + $config_entity->save(); + $this->plugin = \Drupal::service('plugin.manager.migrate.process') + ->createInstance('entity_value', [ + 'entity_type' => 'node_type', + 'langcode' => 'es', + 'field_name' => 'type', + ]); + + $executable = $this->prophesize(MigrateExecutableInterface::class) + ->reveal(); + $row = new Row(); + + // Ensure that the entity is returned if it really exists. + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Langcode can only be used with content entities currently.'); + $this->plugin->transform([$config_entity->id()], $executable, $row, 'dummmy'); + } + /** * Test the EntityLoad plugin throwing. * @@ -161,7 +188,7 @@ class EntityValueTest extends KernelTestBase { */ public function testEntityValueConfig($config) { $this->expectException(\InvalidArgumentException::class); - $plugin = \Drupal::service('plugin.manager.migrate.process') + \Drupal::service('plugin.manager.migrate.process') ->createInstance('entity_value', $config); } -- GitLab