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