Skip to content
Snippets Groups Projects
Commit ca621bc3 authored by Nazar Velychenko's avatar Nazar Velychenko Committed by Ivan Doroshenko
Browse files

Issue #3261274: Throw consistent exceptions on...

Issue #3261274: Throw consistent exceptions on \Drupal\migrate_plus\Plugin\migrate\process\EntityValue process plugin
parent 40013b65
No related branches found
No related tags found
1 merge request!35Issue #3261274: Throw consistent exceptions on \Drupal\migrate_plus\Plugin\migrate\process\EntityValue process plugin
...@@ -151,7 +151,7 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt ...@@ -151,7 +151,7 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt
} }
else { else {
if ($langcode) { 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 { try {
......
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row; use Drupal\migrate\Row;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
/** /**
* Tests the entity_value plugin. * Tests the entity_value plugin.
...@@ -150,6 +152,31 @@ class EntityValueTest extends KernelTestBase { ...@@ -150,6 +152,31 @@ class EntityValueTest extends KernelTestBase {
$this->assertTrue($this->plugin->multiple()); $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. * Test the EntityLoad plugin throwing.
* *
...@@ -161,7 +188,7 @@ class EntityValueTest extends KernelTestBase { ...@@ -161,7 +188,7 @@ class EntityValueTest extends KernelTestBase {
*/ */
public function testEntityValueConfig($config) { public function testEntityValueConfig($config) {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
$plugin = \Drupal::service('plugin.manager.migrate.process') \Drupal::service('plugin.manager.migrate.process')
->createInstance('entity_value', $config); ->createInstance('entity_value', $config);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment