Fix fatal error when sorting by status in activity search
[civicrm-core.git] / tests / phpunit / CRM / Activity / Selector / SearchTest.php
CommitLineData
c2a377b1 1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28/**
29 * Class CRM_Activity_Selector_SearchTest
30 *
31 * @package CiviCRM
32 */
33class CRM_Activity_Selector_SearchTest extends CiviUnitTestCase {
34
35 /**
36 * Test activity search applies a permission based component filter.
37 */
38 public function testActivitySearchComponentPermission() {
39 $this->activityCreate(['activity_type_id' => 'Contribution']);
40 $this->activityCreate(['activity_type_id' => 'Pledge Reminder']);
41 $this->activityCreate(['activity_type_id' => 'Meeting']);
42 $this->setPermissions(['access CiviCRM', 'edit all contacts', 'access CiviContribute']);
43 $queryParams = [['activity_location', '=', 'Baker Street', '', '']];
44 $searchSelector = new CRM_Activity_Selector_Search($queryParams, CRM_Core_Action::VIEW);
45 $this->assertEquals(2, $searchSelector->getTotalCount(NULL));
46 $queryObject = $searchSelector->getQuery();
47 $this->assertEquals("civicrm_activity.location = 'Baker Street'", $queryObject->_where[''][0]);
48 }
49
6b051312 50 public function testActivityOrderBy() {
51 $sortVars = [
52 1 => [
53 'name' => 'activity_date_time',
54 'sort' => 'activity_date_time',
55 'direction' => 2,
56 'title' => 'Date',
57 ],
58 2 => [
59 'name' => 'activity_type_id',
60 'sort' => 'activity_type_id',
61 'direction' => 4,
62 'title' => 'Type',
63 ],
64 3 => [
65 'name' => 'activity_subject',
66 'sort' => 'activity_subject',
67 'direction' => 4,
68 'title' => 'Subject',
69 ],
70 4 => [
71 'name' => 'source_contact',
72 'sort' => 'source_contact',
73 'direction' => 4,
74 'title' => 'Added By',
75 ],
76 5 => [
77 'name' => 'activity_status',
78 'sort' => 'activity_status',
79 'direction' => 1,
80 'title' => 'Status',
81 ],
82 ];
83 $sort = new CRM_Utils_Sort($sortVars, '5_u');
84 $searchSelector = new CRM_Activity_Selector_Search($queryParams, CRM_Core_Action::VIEW);
85 $searchSelector->getRows(4, 0, 50, $sort);
86 }
87
c2a377b1 88}