APIv4-based smart groups
[civicrm-core.git] / tests / phpunit / api / v4 / Entity / SavedSearchTest.php
CommitLineData
4e97c268
CW
1<?php
2
3/*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 |
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
22namespace api\v4\Entity;
23
24use api\v4\UnitTestCase;
25use Civi\Api4\Contact;
26
27/**
28 * @group headless
29 */
30class SavedSearchTest extends UnitTestCase {
31
32 public function testApi4SmartGroup() {
33 $in = Contact::create()->setCheckPermissions(FALSE)->addValue('first_name', 'yes')->addValue('do_not_phone', TRUE)->execute()->first();
34 $out = Contact::create()->setCheckPermissions(FALSE)->addValue('first_name', 'no')->addValue('do_not_phone', FALSE)->execute()->first();
35
36 $savedSearch = civicrm_api4('SavedSearch', 'create', [
37 'values' => [
38 'api_entity' => 'Contact',
39 'api_params' => [
40 'version' => 4,
41 'where' => [
42 ['do_not_phone', '=', TRUE],
43 ],
44 ],
45 ],
46 'chain' => [
47 'group' => ['Group', 'create', ['values' => ['title' => 'Hello Test', 'saved_search_id' => '$id']], 0],
48 ],
49 ])->first();
50
51 // Oops we don't have an api4 syntax yet for selecting contacts in a group.
52 $ins = civicrm_api3('Contact', 'get', ['group' => $savedSearch['group']['name'], 'options' => ['limit' => 0]]);
53 $this->assertArrayHasKey($in['id'], $ins['values']);
54 $this->assertArrayNotHasKey($out['id'], $ins['values']);
55 }
56
57}