From 634dfcee10231ba8946793bd979dd1e7fabebcf6 Mon Sep 17 00:00:00 2001 From: webchick <drupal@webchick.net> Date: Wed, 2 Sep 2015 13:31:55 -0700 Subject: [PATCH] Issue #2560659 by benjy, phenaproxima, neclimdul: Invalidate the Migration destination plugin when overriding with set() --- core/modules/migrate/src/Entity/Migration.php | 4 ++ .../migrate/src/Tests/MigrationTest.php | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 core/modules/migrate/src/Tests/MigrationTest.php diff --git a/core/modules/migrate/src/Entity/Migration.php b/core/modules/migrate/src/Entity/Migration.php index 50ab034ab533..4c1ce524b27b 100644 --- a/core/modules/migrate/src/Entity/Migration.php +++ b/core/modules/migrate/src/Entity/Migration.php @@ -480,6 +480,10 @@ public function set($property_name, $value) { // Invalidate the source plugin. unset($this->sourcePlugin); } + elseif ($property_name === 'destination') { + // Invalidate the destination plugin. + unset($this->destinationPlugin); + } return parent::set($property_name, $value); } diff --git a/core/modules/migrate/src/Tests/MigrationTest.php b/core/modules/migrate/src/Tests/MigrationTest.php new file mode 100644 index 000000000000..a46b830a70b0 --- /dev/null +++ b/core/modules/migrate/src/Tests/MigrationTest.php @@ -0,0 +1,45 @@ +<?php + +namespace Drupal\migrate\Tests; + +use Drupal\migrate\Entity\Migration; +use Drupal\simpletest\KernelTestBase; + +/** + * Tests the migration entity. + * + * @group migrate + * @coversDefaultClass \Drupal\migrate\Entity\Migration + */ +class MigrationTest extends KernelTestBase { + + /** + * Enable field because we're using one of its source plugins. + * + * @var array + */ + public static $modules = ['migrate', 'field']; + + /** + * Tests Migration::set() + * + * @covers ::set() + */ + public function testSetInvalidation() { + $migration = Migration::create([ + 'source' => ['plugin' => 'empty'], + 'destination' => ['plugin' => 'entity:entity_view_mode'], + ]); + $this->assertEqual('empty', $migration->getSourcePlugin()->getPluginId()); + $this->assertEqual('entity:entity_view_mode', $migration->getDestinationPlugin()->getPluginId()); + + // Test the source plugin is invalidated. + $migration->set('source', ['plugin' => 'd6_field']); + $this->assertEqual('d6_field', $migration->getSourcePlugin()->getPluginId()); + + // Test the destination plugin is invalidated. + $migration->set('destination', ['plugin' => 'null']); + $this->assertEqual('null', $migration->getDestinationPlugin()->getPluginId()); + } + +} -- GitLab