Merge pull request #17057 from eileenmcnaughton/email3
[civicrm-core.git] / tests / phpunit / api / v4 / Action / ContactGetTest.php
CommitLineData
19b53e5b
C
1<?php
2
380f3545
TO
3/*
4 +--------------------------------------------------------------------+
7d61e75f 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
7d61e75f
TO
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 * $Id$
18 *
19 */
20
21
19b53e5b
C
22namespace api\v4\Action;
23
24use Civi\Api4\Contact;
25
26/**
27 * @group headless
28 */
29class ContactGetTest extends \api\v4\UnitTestCase {
30
31 public function testGetDeletedContacts() {
32 $last_name = uniqid('deleteContactTest');
33
34 $bob = Contact::create()
35 ->setValues(['first_name' => 'Bob', 'last_name' => $last_name])
36 ->execute()->first();
37
38 $jan = Contact::create()
39 ->setValues(['first_name' => 'Jan', 'last_name' => $last_name])
40 ->execute()->first();
41
42 $del = Contact::create()
43 ->setValues(['first_name' => 'Del', 'last_name' => $last_name, 'is_deleted' => 1])
44 ->execute()->first();
45
46 // Deleted contacts are not fetched by default
47 $this->assertCount(2, Contact::get()->addWhere('last_name', '=', $last_name)->selectRowCount()->execute());
48
49 // You can search for them specifically
50 $contacts = Contact::get()->addWhere('last_name', '=', $last_name)->addWhere('is_deleted', '=', 1)->addSelect('id')->execute();
51 $this->assertEquals($del['id'], $contacts->first()['id']);
52
53 // Or by id
54 $this->assertCount(3, Contact::get()->addWhere('id', 'IN', [$bob['id'], $jan['id'], $del['id']])->selectRowCount()->execute());
55
56 // Putting is_deleted anywhere in the where clause will disable the default
57 $contacts = Contact::get()->addClause('OR', ['last_name', '=', $last_name], ['is_deleted', '=', 0])->addSelect('id')->execute();
58 $this->assertContains($del['id'], $contacts->column('id'));
59 }
60
61}