Merge pull request #16574 from civicrm/5.23
[civicrm-core.git] / tests / phpunit / CRM / Activity / Selector / SearchTest.php
CommitLineData
c2a377b1 1<?php
2/*
3 +--------------------------------------------------------------------+
7d61e75f 4 | Copyright CiviCRM LLC. All rights reserved. |
c2a377b1 5 | |
7d61e75f
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
c2a377b1 9 +--------------------------------------------------------------------+
10 */
11
12/**
13 * Class CRM_Activity_Selector_SearchTest
14 *
15 * @package CiviCRM
16 */
17class CRM_Activity_Selector_SearchTest extends CiviUnitTestCase {
18
19 /**
20 * Test activity search applies a permission based component filter.
21 */
22 public function testActivitySearchComponentPermission() {
23 $this->activityCreate(['activity_type_id' => 'Contribution']);
24 $this->activityCreate(['activity_type_id' => 'Pledge Reminder']);
25 $this->activityCreate(['activity_type_id' => 'Meeting']);
26 $this->setPermissions(['access CiviCRM', 'edit all contacts', 'access CiviContribute']);
27 $queryParams = [['activity_location', '=', 'Baker Street', '', '']];
28 $searchSelector = new CRM_Activity_Selector_Search($queryParams, CRM_Core_Action::VIEW);
29 $this->assertEquals(2, $searchSelector->getTotalCount(NULL));
30 $queryObject = $searchSelector->getQuery();
31 $this->assertEquals("civicrm_activity.location = 'Baker Street'", $queryObject->_where[''][0]);
32 }
33
6b051312 34 public function testActivityOrderBy() {
35 $sortVars = [
36 1 => [
37 'name' => 'activity_date_time',
38 'sort' => 'activity_date_time',
39 'direction' => 2,
40 'title' => 'Date',
41 ],
42 2 => [
43 'name' => 'activity_type_id',
44 'sort' => 'activity_type_id',
45 'direction' => 4,
46 'title' => 'Type',
47 ],
48 3 => [
49 'name' => 'activity_subject',
50 'sort' => 'activity_subject',
51 'direction' => 4,
52 'title' => 'Subject',
53 ],
54 4 => [
55 'name' => 'source_contact',
56 'sort' => 'source_contact',
57 'direction' => 4,
ff3f9641 58 'title' => 'Added by',
6b051312 59 ],
60 5 => [
61 'name' => 'activity_status',
62 'sort' => 'activity_status',
63 'direction' => 1,
64 'title' => 'Status',
65 ],
66 ];
67 $sort = new CRM_Utils_Sort($sortVars, '5_u');
68 $searchSelector = new CRM_Activity_Selector_Search($queryParams, CRM_Core_Action::VIEW);
69 $searchSelector->getRows(4, 0, 50, $sort);
70 }
71
c2a377b1 72}