Merge pull request #14891 from eileenmcnaughton/saved_search
[civicrm-core.git] / tests / phpunit / CRM / Activity / Form / SearchTest.php
1 <?php
2
3 /**
4 * Include dataProvider for tests
5 * @group headless
6 */
7 class CRM_Activity_Form_SearchTest extends CiviUnitTestCase {
8
9 public function setUp() {
10 parent::setUp();
11 $this->individualID = $this->individualCreate();
12 $this->contributionCreate([
13 'contact_id' => $this->individualID,
14 'receive_date' => '2017-01-30',
15 ]);
16 }
17
18 public function tearDown() {
19 $tablesToTruncate = [
20 'civicrm_activity',
21 'civicrm_activity_contact',
22 ];
23 $this->quickCleanup($tablesToTruncate);
24 }
25
26 /**
27 * Test submitted the search form.
28 */
29 public function testSearch() {
30
31 $form = new CRM_Activity_Form_Search();
32 $_SERVER['REQUEST_METHOD'] = 'GET';
33 $form->controller = new CRM_Activity_Controller_Search();
34 $form->preProcess();
35 $form->postProcess();
36 $qfKey = $form->controller->_key;
37 $rows = $form->controller->get('rows');
38 $this->assertEquals([
39 [
40 'contact_id' => '3',
41 'contact_type' => '<a href="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
42 'sort_name' => 'Anderson, Anthony',
43 'display_name' => 'Mr. Anthony Anderson II',
44 'activity_id' => '1',
45 'activity_date_time' => '2017-01-30 00:00:00',
46 'activity_status_id' => '2',
47 'activity_status' => 'Completed',
48 'activity_subject' => '$ 100.00 - SSF',
49 'source_record_id' => '1',
50 'activity_type_id' => '6',
51 'activity_type' => 'Contribution',
52 'activity_is_test' => '0',
53 'target_contact_name' => [],
54 'assignee_contact_name' => [],
55 'source_contact_id' => '3',
56 'source_contact_name' => 'Anderson, Anthony',
57 'checkbox' => 'mark_x_1',
58 'mailingId' => '',
59 'action' => '<span><a href="/index.php?q=civicrm/contact/view/contribution&amp;action=view&amp;reset=1&amp;id=1&amp;cid=3&amp;context=search&amp;searchContext=activity&amp;key=' . $qfKey . '" class="action-item crm-hover-button" title=\'View Activity\' >View</a></span>',
60 'campaign' => NULL,
61 'campaign_id' => NULL,
62 'repeat' => '',
63 ],
64 ], $rows);
65 }
66
67 /**
68 * Test the Qill for activity Date time.
69 *
70 * @dataProvider getSearchCriteria
71 *
72 * @param array $searchCriteria
73 * @param array $expectedQill
74 */
75 public function testQill($searchCriteria, $expectedQill) {
76 $selector = new CRM_Activity_Selector_Search($searchCriteria);
77 $this->assertEquals($expectedQill, $selector->getQILL());
78 }
79
80 /**
81 * Get criteria for activity testing.
82 */
83 public function getSearchCriteria() {
84
85 // We have to define format because tests crash trying to access the config param from the dataProvider
86 // perhaps because there is no property on config?
87 $format = '%B %E%f, %Y %l:%M %P';
88 $dates['ending_60.day'] = CRM_Utils_Date::getFromTo('ending_60.day', NULL, NULL);
89 $dates['earlier.year'] = CRM_Utils_Date::getFromTo('earlier.year', NULL, NULL);
90 $dates['greater.year'] = CRM_Utils_Date::getFromTo('greater.year', NULL, NULL);
91 return [
92 [
93 'search_criteria' => [
94 ['activity_date_time_relative', '=', 'ending_60.day', 0, 0],
95 ],
96 'expected_qill' => [['Activity Date is Last 60 days including today (between ' . CRM_Utils_Date::customFormat($dates['ending_60.day'][0], $format) . ' and ' . CRM_Utils_Date::customFormat($dates['ending_60.day'][1], $format) . ')']],
97 ],
98 [
99 'search_criteria' => [
100 ['activity_date_time_relative', '=', 'earlier.year', 0, 0],
101 ],
102 'expected_qill' => [['Activity Date is To end of previous calendar year (to ' . CRM_Utils_Date::customFormat($dates['earlier.year'][1], $format) . ')']],
103 ],
104 [
105 'search_criteria' => [
106 ['activity_date_time_relative', '=', 'greater.year', 0, 0],
107 ],
108 'expected_qill' => [['Activity Date is From start of current calendar year (from ' . CRM_Utils_Date::customFormat($dates['greater.year'][0], $format) . ')']],
109 ],
110 [
111 'search_criteria' => [
112 ['activity_date_time_low', '=', '2019-03-05', 0, 0],
113 ['activity_date_time_high', '=', '2019-03-27', 0, 0],
114 ],
115 'expected_qill' => [['Activity Date - greater than or equal to "March 5th, 2019 12:00 AM" AND less than or equal to "March 27th, 2019 11:59 PM"']],
116 ],
117 [
118 'search_criteria' => [
119 ['activity_status_id', '=', ['IN' => ['1', '2']], 0, 0],
120 ],
121 'expected_qill' => [['Activity Status In Scheduled, Completed']],
122 ],
123 ];
124 }
125
126 }