Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
3 | namespace api\v4\Action; | |
4 | ||
5 | use Civi\Api4\Contact; | |
6 | ||
7 | /** | |
8 | * @group headless | |
9 | */ | |
10 | class ContactGetTest extends \api\v4\UnitTestCase { | |
11 | ||
12 | public function testGetDeletedContacts() { | |
13 | $last_name = uniqid('deleteContactTest'); | |
14 | ||
15 | $bob = Contact::create() | |
16 | ->setValues(['first_name' => 'Bob', 'last_name' => $last_name]) | |
17 | ->execute()->first(); | |
18 | ||
19 | $jan = Contact::create() | |
20 | ->setValues(['first_name' => 'Jan', 'last_name' => $last_name]) | |
21 | ->execute()->first(); | |
22 | ||
23 | $del = Contact::create() | |
24 | ->setValues(['first_name' => 'Del', 'last_name' => $last_name, 'is_deleted' => 1]) | |
25 | ->execute()->first(); | |
26 | ||
27 | // Deleted contacts are not fetched by default | |
28 | $this->assertCount(2, Contact::get()->addWhere('last_name', '=', $last_name)->selectRowCount()->execute()); | |
29 | ||
30 | // You can search for them specifically | |
31 | $contacts = Contact::get()->addWhere('last_name', '=', $last_name)->addWhere('is_deleted', '=', 1)->addSelect('id')->execute(); | |
32 | $this->assertEquals($del['id'], $contacts->first()['id']); | |
33 | ||
34 | // Or by id | |
35 | $this->assertCount(3, Contact::get()->addWhere('id', 'IN', [$bob['id'], $jan['id'], $del['id']])->selectRowCount()->execute()); | |
36 | ||
37 | // Putting is_deleted anywhere in the where clause will disable the default | |
38 | $contacts = Contact::get()->addClause('OR', ['last_name', '=', $last_name], ['is_deleted', '=', 0])->addSelect('id')->execute(); | |
39 | $this->assertContains($del['id'], $contacts->column('id')); | |
40 | } | |
41 | ||
42 | } |