4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace api\v
4\Action
;
24 use api\v
4\UnitTestCase
;
25 use Civi\Api4\Activity
;
26 use Civi\Api4\Contact
;
31 * This class tests a series of complex query situations described in the
32 * initial APIv4 specification
34 class ComplexQueryTest
extends UnitTestCase
{
36 public function setUpHeadless() {
39 'civicrm_activity_contact',
41 $this->cleanup(['tablesToTruncate' => $relatedTables]);
42 $this->loadDataSet('DefaultDataSet');
44 return parent
::setUpHeadless();
48 * Fetch all phone call activities
49 * Expects at least one activity loaded from the data set.
51 public function testGetAllHousingSupportActivities() {
52 $results = Activity
::get()
53 ->setCheckPermissions(FALSE)
54 ->addWhere('activity_type_id:name', '=', 'Phone Call')
57 $this->assertGreaterThan(0, count($results));
63 public function testGetWithCount() {
64 $myName = uniqid('count');
65 for ($i = 1; $i <= 20; ++
$i) {
67 ->addValue('first_name', "Contact $i")
68 ->addValue('last_name', $myName)
69 ->setCheckPermissions(FALSE)->execute();
72 $get1 = Contact
::get()
73 ->addWhere('last_name', '=', $myName)
75 ->addSelect('first_name')
78 ->setCheckPermissions(FALSE)->execute();
80 $this->assertEquals(20, $get1->count());
81 $this->assertCount(10, (array) $get1);
86 * Fetch contacts named 'Bob' and all of their blue activities
88 public function testGetAllBlueActivitiesForBobs() {
93 * Get all contacts in a zipcode and return their Home or Work email addresses
95 public function testGetHomeOrWorkEmailsForContactsWithZipcode() {
100 * Fetch all activities where Bob is the assignee or source
102 public function testGetActivitiesWithBobAsAssigneeOrSource() {
107 * Get all contacts which
108 * (a) have address in zipcode 94117 or 94118 or in city "San Francisco","LA"
110 * (b) are not deceased and
111 * (c) have a custom-field "most_important_issue=Environment".
113 public function testAWholeLotOfConditions() {
118 * Get participants who attended CiviCon 2012 but not CiviCon 2013.
119 * Return their name and email.
121 public function testGettingNameAndEmailOfAttendeesOfCiviCon2012Only() {