Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 5 | | |
6 | +--------------------------------------------------------------------+ | |
f299f7db | 7 | | Copyright CiviCRM LLC (c) 2004-2020 | |
380f3545 TO |
8 | +--------------------------------------------------------------------+ |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
f299f7db | 32 | * @copyright CiviCRM LLC (c) 2004-2020 |
380f3545 TO |
33 | * $Id$ |
34 | * | |
35 | */ | |
36 | ||
37 | ||
19b53e5b C |
38 | namespace api\v4\Action; |
39 | ||
40 | use Civi\Api4\Contact; | |
41 | ||
42 | /** | |
43 | * @group headless | |
44 | */ | |
45 | class ContactGetTest extends \api\v4\UnitTestCase { | |
46 | ||
47 | public function testGetDeletedContacts() { | |
48 | $last_name = uniqid('deleteContactTest'); | |
49 | ||
50 | $bob = Contact::create() | |
51 | ->setValues(['first_name' => 'Bob', 'last_name' => $last_name]) | |
52 | ->execute()->first(); | |
53 | ||
54 | $jan = Contact::create() | |
55 | ->setValues(['first_name' => 'Jan', 'last_name' => $last_name]) | |
56 | ->execute()->first(); | |
57 | ||
58 | $del = Contact::create() | |
59 | ->setValues(['first_name' => 'Del', 'last_name' => $last_name, 'is_deleted' => 1]) | |
60 | ->execute()->first(); | |
61 | ||
62 | // Deleted contacts are not fetched by default | |
63 | $this->assertCount(2, Contact::get()->addWhere('last_name', '=', $last_name)->selectRowCount()->execute()); | |
64 | ||
65 | // You can search for them specifically | |
66 | $contacts = Contact::get()->addWhere('last_name', '=', $last_name)->addWhere('is_deleted', '=', 1)->addSelect('id')->execute(); | |
67 | $this->assertEquals($del['id'], $contacts->first()['id']); | |
68 | ||
69 | // Or by id | |
70 | $this->assertCount(3, Contact::get()->addWhere('id', 'IN', [$bob['id'], $jan['id'], $del['id']])->selectRowCount()->execute()); | |
71 | ||
72 | // Putting is_deleted anywhere in the where clause will disable the default | |
73 | $contacts = Contact::get()->addClause('OR', ['last_name', '=', $last_name], ['is_deleted', '=', 0])->addSelect('id')->execute(); | |
74 | $this->assertContains($del['id'], $contacts->column('id')); | |
75 | } | |
76 | ||
77 | } |