Merge pull request #17843 from civicrm/5.28
[civicrm-core.git] / tests / phpunit / api / v4 / Action / ComplexQueryTest.php
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
22 namespace api\v4\Action;
23
24 use api\v4\UnitTestCase;
25 use Civi\Api4\Activity;
26 use Civi\Api4\Contact;
27
28 /**
29 * @group headless
30 *
31 * This class tests a series of complex query situations described in the
32 * initial APIv4 specification
33 */
34 class ComplexQueryTest extends UnitTestCase {
35
36 public function setUpHeadless() {
37 $relatedTables = [
38 'civicrm_activity',
39 'civicrm_activity_contact',
40 ];
41 $this->cleanup(['tablesToTruncate' => $relatedTables]);
42 $this->loadDataSet('DefaultDataSet');
43
44 return parent::setUpHeadless();
45 }
46
47 /**
48 * Fetch all phone call activities
49 * Expects at least one activity loaded from the data set.
50 */
51 public function testGetAllHousingSupportActivities() {
52 $results = Activity::get()
53 ->setCheckPermissions(FALSE)
54 ->addWhere('activity_type_id:name', '=', 'Phone Call')
55 ->execute();
56
57 $this->assertGreaterThan(0, count($results));
58 }
59
60 /**
61 *
62 */
63 public function testGetWithCount() {
64 $myName = uniqid('count');
65 for ($i = 1; $i <= 20; ++$i) {
66 Contact::create()
67 ->addValue('first_name', "Contact $i")
68 ->addValue('last_name', $myName)
69 ->setCheckPermissions(FALSE)->execute();
70 }
71
72 $get1 = Contact::get()
73 ->addWhere('last_name', '=', $myName)
74 ->selectRowCount()
75 ->addSelect('first_name')
76 ->setLimit(10)
77 ->setDebug(TRUE)
78 ->setCheckPermissions(FALSE)->execute();
79
80 $this->assertEquals(20, $get1->count());
81 $this->assertCount(10, (array) $get1);
82
83 }
84
85 /**
86 * Fetch contacts named 'Bob' and all of their blue activities
87 */
88 public function testGetAllBlueActivitiesForBobs() {
89
90 }
91
92 /**
93 * Get all contacts in a zipcode and return their Home or Work email addresses
94 */
95 public function testGetHomeOrWorkEmailsForContactsWithZipcode() {
96
97 }
98
99 /**
100 * Fetch all activities where Bob is the assignee or source
101 */
102 public function testGetActivitiesWithBobAsAssigneeOrSource() {
103
104 }
105
106 /**
107 * Get all contacts which
108 * (a) have address in zipcode 94117 or 94118 or in city "San Francisco","LA"
109 * and
110 * (b) are not deceased and
111 * (c) have a custom-field "most_important_issue=Environment".
112 */
113 public function testAWholeLotOfConditions() {
114
115 }
116
117 /**
118 * Get participants who attended CiviCon 2012 but not CiviCon 2013.
119 * Return their name and email.
120 */
121 public function testGettingNameAndEmailOfAttendeesOfCiviCon2012Only() {
122
123 }
124
125 }