-
-
Notifications
You must be signed in to change notification settings - Fork 827
/
Copy pathExceptionTest.php
66 lines (61 loc) · 2.52 KB
/
ExceptionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Test class for Dedupe exceptions.
*
* @package CiviCRM_APIv3
* @group headless
*/
class api_v3_ExceptionTest extends CiviUnitTestCase {
/**
* Sets up the fixture, for example, opens a network connection.
*
* This method is called before a test is executed.
*/
protected function setUp(): void {
parent::setUp();
$this->useTransaction(TRUE);
}
/**
* Test that when a dedupe exception is created the pair are saved from the merge cache.
*/
public function testCreatingAnExceptionRemovesFromCachedMergePairs(): void {
$contact1 = $this->individualCreate();
$contact2 = $this->individualCreate();
$defaultRuleGroupID = $this->callAPISuccess('RuleGroup', 'getvalue', [
'contact_type' => 'Individual',
'used' => 'Unsupervised',
'return' => 'id',
'options' => ['limit' => 1],
]);
$dupes = $this->callAPISuccess('Dedupe', 'getduplicates', ['rule_group_id' => $defaultRuleGroupID]);
$this->assertEquals(1, $dupes['count']);
$this->callAPISuccess('Exception', 'create', ['contact_id1' => $contact1, 'contact_id2' => $contact2]);
$this->assertEquals(0, CRM_Core_DAO::singleValueQuery('
SELECT count(*) FROM civicrm_prevnext_cache
WHERE (entity_id1 = ' . $contact1 . ' AND entity_id2 = ' . $contact2 . ')
OR (entity_id1 = ' . $contact2 . ' AND entity_id2 = ' . $contact1 . ')'
));
$dupes = $this->callAPISuccess('Dedupe', 'getduplicates', ['rule_group_id' => $defaultRuleGroupID]);
$this->assertEquals(0, $dupes['count']);
}
/**
* Per the ajax code there is an expectation the lower id will be contact 1 - ensure api handles this.
*
* @throws \Exception
*/
public function testExceptionSavesLowerIDFirst(): void {
$contact1 = $this->individualCreate();
$contact2 = $this->individualCreate();
$this->callAPISuccess('Exception', 'create', ['contact_id1' => $contact2, 'contact_id2' => $contact1]);
$this->callAPISuccessGetSingle('Exception', ['contact_id1' => $contact1, 'contact_id2' => $contact2]);
}
}