Commit | Line | Data |
---|---|---|
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 |
22 | namespace api\v4\Action; |
23 | ||
24 | use Civi\Api4\Contact; | |
25 | ||
26 | /** | |
27 | * @group headless | |
28 | */ | |
29 | class 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 | ||
f8bf8e26 CW |
61 | public function testGetWithLimit() { |
62 | $last_name = uniqid('getWithLimitTest'); | |
63 | ||
64 | $bob = Contact::create() | |
65 | ->setValues(['first_name' => 'Bob', 'last_name' => $last_name]) | |
66 | ->execute()->first(); | |
67 | ||
68 | $jan = Contact::create() | |
69 | ->setValues(['first_name' => 'Jan', 'last_name' => $last_name]) | |
70 | ->execute()->first(); | |
71 | ||
72 | $dan = Contact::create() | |
73 | ->setValues(['first_name' => 'Dan', 'last_name' => $last_name]) | |
74 | ->execute()->first(); | |
75 | ||
76 | $num = Contact::get()->setCheckPermissions(FALSE)->selectRowCount()->execute()->count(); | |
77 | $this->assertCount($num - 1, Contact::get()->setCheckPermissions(FALSE)->setLimit(0)->setOffset(1)->execute()); | |
78 | $this->assertCount($num - 2, Contact::get()->setCheckPermissions(FALSE)->setLimit(0)->setOffset(2)->execute()); | |
79 | $this->assertCount(2, Contact::get()->setCheckPermissions(FALSE)->setLimit(2)->setOffset(0)->execute()); | |
80 | } | |
81 | ||
19b53e5b | 82 | } |