From bc0f396570d0ccebc6594d06c6f2247ceb371d05 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 12 Jul 2016 20:46:12 +1200 Subject: [PATCH] CRM-19035 Tests for organization get dupes (just adding general coverage around the area - esp as there is a perf bug in this query I also want to fix). --- tests/phpunit/CRM/Dedupe/MergerTest.php | 114 ++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/tests/phpunit/CRM/Dedupe/MergerTest.php b/tests/phpunit/CRM/Dedupe/MergerTest.php index c9cc7c67fc..9b120d08a9 100644 --- a/tests/phpunit/CRM/Dedupe/MergerTest.php +++ b/tests/phpunit/CRM/Dedupe/MergerTest.php @@ -302,6 +302,98 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase { ), $pairs); } + /** + * Test function that gets organization pairs. + * + * Note the rule will match on organization_name OR email - hence lots of matches. + */ + public function testGetOrganizationMatches() { + $this->setupMatchData(); + $ruleGroups = $this->callAPISuccessGetSingle('RuleGroup', array('contact_type' => 'Organization', 'used' => 'Supervised')); + + $pairs = CRM_Dedupe_Merger::getDuplicatePairs( + $ruleGroups['id'], + NULL, + TRUE, + 25, + FALSE + ); + + $this->assertEquals(array( + 0 => array( + 'srcID' => $this->contacts[5]['id'], + 'srcName' => 'Walt Disney Ltd', + 'dstID' => $this->contacts[4]['id'], + 'dstName' => 'Walt Disney Ltd', + 'weight' => 20, + 'canMerge' => TRUE, + ), + 1 => array( + 'srcID' => $this->contacts[7]['id'], + 'srcName' => 'Walt Disney', + 'dstID' => $this->contacts[6]['id'], + 'dstName' => 'Walt Disney', + 'weight' => 10, + 'canMerge' => TRUE, + ), + 2 => array( + 'srcID' => $this->contacts[6]['id'], + 'srcName' => 'Walt Disney', + 'dstID' => $this->contacts[4]['id'], + 'dstName' => 'Walt Disney Ltd', + 'weight' => 10, + 'canMerge' => TRUE, + ), + 3 => array( + 'srcID' => $this->contacts[6]['id'], + 'srcName' => 'Walt Disney', + 'dstID' => $this->contacts[5]['id'], + 'dstName' => 'Walt Disney Ltd', + 'weight' => 10, + 'canMerge' => TRUE, + ), + ), $pairs); + } + + /** + * Test function that gets organization duplicate pairs. + */ + public function testGetOrganizationMatchesInGroup() { + $this->setupMatchData(); + $ruleGroups = $this->callAPISuccessGetSingle('RuleGroup', array('contact_type' => 'Organization', 'used' => 'Supervised')); + + $groupID = $this->groupCreate(array('title' => 'she-mice')); + + $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $this->contacts[4]['id'])); + + $pairs = CRM_Dedupe_Merger::getDuplicatePairs( + $ruleGroups['id'], + $groupID, + TRUE, + 25, + FALSE + ); + + $this->assertEquals(array( + 0 => array( + 'srcID' => $this->contacts[5]['id'], + 'srcName' => 'Walt Disney Ltd', + 'dstID' => $this->contacts[4]['id'], + 'dstName' => 'Walt Disney Ltd', + 'weight' => 20, + 'canMerge' => TRUE, + ), + 1 => array( + 'srcID' => $this->contacts[6]['id'], + 'srcName' => 'Walt Disney', + 'dstID' => $this->contacts[4]['id'], + 'dstName' => 'Walt Disney Ltd', + 'weight' => 10, + 'canMerge' => TRUE, + ), + ), $pairs); + } + /** * Test function that gets duplicate pairs. * @@ -365,6 +457,28 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase { $contactID = $this->individualCreate($fixture); $this->contacts[] = array_merge($fixture, array('id' => $contactID)); } + $organizationFixtures = array( + array( + 'organization_name' => 'Walt Disney Ltd', + 'email' => 'walt@disney.com', + ), + array( + 'organization_name' => 'Walt Disney Ltd', + 'email' => 'walt@disney.com', + ), + array( + 'organization_name' => 'Walt Disney', + 'email' => 'walt@disney.com', + ), + array( + 'organization_name' => 'Walt Disney', + 'email' => 'walter@disney.com', + ), + ); + foreach ($organizationFixtures as $fixture) { + $contactID = $this->organizationCreate($fixture); + $this->contacts[] = array_merge($fixture, array('id' => $contactID)); + } } -- 2.25.1