diff --git a/core/modules/migrate/src/Exception/MigrateEntityViolationException.php b/core/modules/migrate/src/Exception/MigrateEntityViolationException.php deleted file mode 100644 index 64422db..0000000 --- a/core/modules/migrate/src/Exception/MigrateEntityViolationException.php +++ /dev/null @@ -1,31 +0,0 @@ -getMessage(); - } - parent::__construct(implode(', ', $messages)); - } - -} diff --git a/core/modules/migrate/src/Exception/ValidationException.php b/core/modules/migrate/src/Exception/ValidationException.php new file mode 100644 index 0000000..7b71b77 --- /dev/null +++ b/core/modules/migrate/src/Exception/ValidationException.php @@ -0,0 +1,31 @@ +getMessage(); + } + parent::__construct(implode(', ', $messages)); + } + +} diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index 2b79099..0c3cfdd 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -10,7 +10,7 @@ use Drupal\Core\TypedData\TranslatableInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\migrate\Audit\HighestIdInterface; -use Drupal\migrate\Exception\MigrateEntityViolationException; +use Drupal\migrate\Exception\ValidationException; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\MigrateIdMapInterface; @@ -123,7 +123,7 @@ protected function save(ContentEntityInterface $entity, array $old_destination_i * TRUE if validation is needed, FALSE otherwise. */ protected function needsValidation() { - return isset($this->configuration['validate']) ? TRUE : FALSE; + return isset($this->configuration['validate']); } /** @@ -132,13 +132,13 @@ protected function needsValidation() { * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity to validate. * - * @throws \Drupal\migrate\Exception\MigrateEntityViolationException + * @throws \Drupal\migrate\Exception\ValidationException */ protected function validateEntity(ContentEntityInterface $entity) { /** @var \Drupal\Core\Entity\EntityConstraintViolationListInterface $violations */ $violations = $entity->validate(); if (count($violations)) { - throw new MigrateEntityViolationException($violations); + throw new ValidationException($violations); } } diff --git a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php index f595bf3..7d72c43 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php @@ -25,13 +25,6 @@ class MigrateEntityContentValidationTest extends KernelTestBase implements Migra public static $modules = ['migrate', 'system', 'user', 'entity_test']; /** - * Migration to run. - * - * @var \Drupal\migrate\Plugin\MigrationInterface - */ - protected $migration; - - /** * Messages accumulated during the migration run. * * @var array @@ -46,10 +39,15 @@ protected function setUp() { $this->installConfig(['system', 'user']); $this->installEntitySchema('entity_test'); $this->installEntitySchema('user'); + \Drupal::service('event_dispatcher')->addListener(MigrateEvents::IDMAP_MESSAGE, array($this, 'mapMessageRecorder')); + // Make sure that a user with uid 2 exists. + User::create(['name' => $this->randomMachineName(), 'uid' => 2, 'status' => 1])->save(); + } - // Test user. - User::create(['name' => 'TestUser', 'uid' => 2, 'status' => 1])->save(); - + /** + * Tests entity validation. + */ + public function testValidation() { // Migration definition. $definition = [ 'migration_tags' => ['ValidationTest'], @@ -86,17 +84,10 @@ protected function setUp() { 'validate' => TRUE, ], ]; + $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition); - $this->migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition); - } - - /** - * Tests entity validation. - */ - public function testValidation() { - \Drupal::service('event_dispatcher')->addListener(MigrateEvents::IDMAP_MESSAGE, array($this, 'mapMessageRecorder')); // Execute the migration. - $executable = new MigrateExecutable($this->migration, $this); + $executable = new MigrateExecutable($migration); $executable->import(); // First message should have 2 validation errors.