diff --git a/src/Plugin/migrate/process/EntityValue.php b/src/Plugin/migrate/process/EntityValue.php index 77a7358ce5e75fcf3b2fce1761a7fc2a4c21dcd7..75891b1aa837b86b9afc204f874a70532850bd7f 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 e1e0962deaaf32777b78c4779fb647dd2fdca03f..9ffe66570bbd31a291d20e731991cf1c06c90d3b 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); }