contactIDs as $contactId) { $this->contactDelete($contactId); } if ($this->groupID) { $this->callAPISuccess('group', 'delete', array('id' => $this->groupID)); } parent::tearDown(); } /** * Test the unsupervised dedupe rule against a group. * * @throws \Exception */ public function testUnsupervisedDupes() { // make dupe checks based on based on following contact sets: // FIRST - LAST - EMAIL // --------------------------------- // robin - hood - robin@example.com // robin - hood - hood@example.com // robin - dale - robin@example.com // little - dale - dale@example.com // will - dale - dale@example.com // will - dale - will@example.com // will - dale - will@example.com $this->setupForGroupDedupe(); $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', array('is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Unsupervised')); $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID); $this->assertEquals(count($foundDupes), 3, 'Check Individual-Fuzzy dupe rule for dupesInGroup().'); } /** * Test the supervised dedupe rule against a group. * * @throws \Exception */ public function testSupervisedDupes() { $this->setupForGroupDedupe(); $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', array('s_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Supervised')); $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID); // ------------------------------------------------------------------------- // default dedupe rule: threshold = 20 => (First + Last + Email) Matches ( 1 pair ) // -------------------------------------------------------------------------- // will - dale - will@example.com // will - dale - will@example.com // so 1 pair for - first + last + mail $this->assertEquals(count($foundDupes), 1, 'Check Individual-Fuzzy dupe rule for dupesInGroup().'); } /** * Test dupesByParams function. */ public function testDupesByParams() { // make dupe checks based on based on following contact sets: // FIRST - LAST - EMAIL // --------------------------------- // robin - hood - robin@example.com // robin - hood - hood@example.com // robin - dale - robin@example.com // little - dale - dale@example.com // will - dale - dale@example.com // will - dale - will@example.com // will - dale - will@example.com // contact data set // FIXME: move create params to separate function $params = array( array( 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'robin@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'robin', 'last_name' => 'dale', 'email' => 'robin@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'little', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual', ), ); $count = 1; foreach ($params as $param) { $contact = $this->callAPISuccess('contact', 'create', $param); $params = array( 'contact_id' => $contact['id'], 'street_address' => 'Ambachtstraat 23', 'location_type_id' => 1, ); $this->callAPISuccess('address', 'create', $params); $contactIds[$count++] = $contact['id']; } // verify that all contacts have been created separately $this->assertEquals(count($contactIds), 7, 'Check for number of contacts.'); $dao = new CRM_Dedupe_DAO_RuleGroup(); $dao->contact_type = 'Individual'; $dao->used = 'General'; $dao->is_default = 1; $dao->find(TRUE); $fields = array( 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'street_address' => 'Ambachtstraat 23', ); CRM_Core_TemporaryErrorScope::useException(); $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($fields, 'Individual', 'General'); // Check with default Individual-General rule $this->assertEquals(count($ids), 2, 'Check Individual-General rule for dupesByParams().'); // delete all created contacts foreach ($contactIds as $contactId) { $this->contactDelete($contactId); } } /** * Set up a group of dedupable contacts. */ protected function setupForGroupDedupe() { $params = array( 'name' => 'Dupe Group', 'title' => 'New Test Dupe Group', 'domain_id' => 1, 'is_active' => 1, 'visibility' => 'Public Pages', ); $result = $this->callAPISuccess('group', 'create', $params); $this->groupID = $result['id']; $params = array( array( 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'robin@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'robin', 'last_name' => 'dale', 'email' => 'robin@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'little', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual', ), array( 'first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual', ), ); $count = 1; foreach ($params as $param) { $contact = $this->callAPISuccess('contact', 'create', $param); $this->contactIDs[$count++] = $contact['id']; $grpParams = array( 'contact_id' => $contact['id'], 'group_id' => $this->groupID, ); $this->callAPISuccess('group_contact', 'create', $grpParams); } // verify that all contacts have been created separately $this->assertEquals(count($this->contactIDs), 7, 'Check for number of contacts.'); } }