From 8c813b1e5bb1f255792b30afe63592f1998ff9cc Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Wed, 26 Oct 2016 12:49:44 -0700
Subject: [PATCH] Issue #2812625 by quietone: contact_category should dedupe
 contact_form not user_role

---
 .../migration_templates/contact_category.yml  |  4 ++--
 .../Migrate/d6/MigrateContactCategoryTest.php | 23 +++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/core/modules/contact/migration_templates/contact_category.yml b/core/modules/contact/migration_templates/contact_category.yml
index ce7ce9931df8..0174de491641 100644
--- a/core/modules/contact/migration_templates/contact_category.yml
+++ b/core/modules/contact/migration_templates/contact_category.yml
@@ -12,8 +12,8 @@ process:
       source: category
     -
       plugin: dedupe_entity
-      entity_type: user_role
-      field: cid
+      entity_type: contact_form
+      field: id
       length: 32
   label: category
   recipients: recipients
diff --git a/core/modules/contact/tests/src/Kernel/Migrate/d6/MigrateContactCategoryTest.php b/core/modules/contact/tests/src/Kernel/Migrate/d6/MigrateContactCategoryTest.php
index d613cacdf5b6..e40f0bdd49a3 100644
--- a/core/modules/contact/tests/src/Kernel/Migrate/d6/MigrateContactCategoryTest.php
+++ b/core/modules/contact/tests/src/Kernel/Migrate/d6/MigrateContactCategoryTest.php
@@ -47,6 +47,29 @@ public function testContactCategory() {
     $this->assertIdentical(array('fortyninechars@example.com'), $contact_form->getRecipients());
     $this->assertIdentical('', $contact_form->getReply());
     $this->assertIdentical(2, $contact_form->getWeight());
+
+    // Test there are no duplicated roles.
+    $contact_forms = [
+      'website_feedback1',
+      'some_other_category1',
+      'a_category_much_longer_than_thir1',
+    ];
+    $this->assertEmpty(ContactForm::loadMultiple($contact_forms));
+
+    /*
+     * Remove the map row for the Website feedback contact form so that it
+     * can be migrated again.
+     */
+    $id_map = $this->getMigration('contact_category')->getIdMap();
+    $id_map->delete(['cid' => '1']);
+    $this->executeMigration('contact_category');
+
+    // Test there is a duplicate Website feedback form.
+    $contact_form = ContactForm::load('website_feedback1');
+    $this->assertSame('Website feedback', $contact_form->label());
+    $this->assertSame(array('admin@example.com'), $contact_form->getRecipients());
+    $this->assertSame('', $contact_form->getReply());
+    $this->assertSame(0, $contact_form->getWeight());
   }
 
 }
-- 
GitLab