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
Loading
Loading
Loading
Loading
+1 −1
Changes for src/Plugin/migrate/process/EntityValue.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -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 {
+28 −1
Changes for tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php: 28 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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);
  }