4 * Include dataProvider for tests
7 class CRM_Activity_Form_SearchTest
extends CiviUnitTestCase
{
9 public function setUp(): void
{
11 $this->individualID
= $this->individualCreate();
12 $this->contributionCreate([
13 'contact_id' => $this->individualID
,
14 'receive_date' => '2017-01-30',
18 public function tearDown(): void
{
21 'civicrm_activity_contact',
23 $this->quickCleanup($tablesToTruncate);
28 * Test submitted the search form.
30 * @throws \CRM_Core_Exception
31 * @throws \CiviCRM_API3_Exception
33 public function testSearch(): void
{
35 $form = new CRM_Activity_Form_Search();
36 $_SERVER['REQUEST_METHOD'] = 'GET';
37 $form->controller
= new CRM_Activity_Controller_Search();
40 $qfKey = $form->controller
->_key
;
41 $rows = $form->controller
->get('rows');
45 'contact_type' => '<a href="/index.php?q=civicrm/contact/view&reset=1&cid=3" data-tooltip-url="/index.php?q=civicrm/profile/view&reset=1&gid=7&id=3&snippet=4&is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
46 'sort_name' => 'Anderson, Anthony',
47 'display_name' => 'Mr. Anthony Anderson II',
49 'activity_date_time' => '2017-01-30 00:00:00',
50 'activity_status_id' => '2',
51 'activity_status' => 'Completed',
52 'activity_subject' => '$ 100.00 - SSF',
53 'source_record_id' => '1',
54 'activity_type_id' => '6',
55 'activity_type' => 'Contribution',
56 'activity_is_test' => '0',
57 'target_contact_name' => [],
58 'assignee_contact_name' => [],
59 'source_contact_id' => '3',
60 'source_contact_name' => 'Anderson, Anthony',
61 'checkbox' => 'mark_x_1',
63 'action' => '<span><a href="/index.php?q=civicrm/contact/view/contribution&action=view&reset=1&id=1&cid=3&context=search&searchContext=activity&key=' . $qfKey . '" class="action-item crm-hover-button" title=\'View Activity\' >View</a></span>',
65 'campaign_id' => NULL,
67 'contact_sub_type' => NULL,
68 'activity_campaign_id' => NULL,
69 'activity_engagement_level' => NULL,
76 * Test the Qill for activity Date time.
78 public function testQill() {
79 foreach ($this->getSearchCriteria() as $test_name => $data) {
80 $selector = new CRM_Activity_Selector_Search($data['search_criteria']);
81 $this->assertEquals($data['expected_qill'], $selector->getQILL(), "Failed for data set: $test_name");
86 * Get criteria for activity testing.
88 public function getSearchCriteria() {
89 $format = \Civi
::settings()->get('dateformatDatetime');
90 $dates['ending_60.day'] = CRM_Utils_Date
::getFromTo('ending_60.day', NULL, NULL);
91 $dates['earlier.year'] = CRM_Utils_Date
::getFromTo('earlier.year', NULL, NULL);
92 $dates['greater.year'] = CRM_Utils_Date
::getFromTo('greater.year', NULL, NULL);
95 'search_criteria' => [
96 ['activity_date_time_relative', '=', 'ending_60.day', 0, 0],
98 '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) . ')']],
100 'end of previous year' => [
101 'search_criteria' => [
102 ['activity_date_time_relative', '=', 'earlier.year', 0, 0],
104 'expected_qill' => [['Activity Date is To end of previous calendar year (to ' . CRM_Utils_Date
::customFormat($dates['earlier.year'][1], $format) . ')']],
106 'start of current year' => [
107 'search_criteria' => [
108 ['activity_date_time_relative', '=', 'greater.year', 0, 0],
110 'expected_qill' => [['Activity Date is From start of current calendar year (from ' . CRM_Utils_Date
::customFormat($dates['greater.year'][0], $format) . ')']],
113 'search_criteria' => [
114 ['activity_date_time_low', '=', '2019-03-05', 0, 0],
115 ['activity_date_time_high', '=', '2019-03-27', 0, 0],
117 '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"']],
119 'status is one of' => [
120 'search_criteria' => [
121 ['activity_status_id', '=', ['IN' => ['1', '2']], 0, 0],
123 'expected_qill' => [['Activity Status In Scheduled, Completed']],
129 * This just checks there's no errors. It doesn't perform any tasks.
130 * It's a little bit like choosing an action from the dropdown.
131 * @dataProvider taskControllerProvider
134 public function testTaskController(int $task) {
135 // It gets the task from the POST var
136 $oldtask = $_POST['task'] ??
NULL;
137 $_POST['task'] = $task;
139 // yes it's the string 'null'
140 new CRM_Activity_Controller_Search('Find Activities', TRUE, 'null');
143 if (is_null($oldtask)) {
144 unset($_POST['task']);
147 $_POST['task'] = $oldtask;
152 * dataprovider for testTaskController
155 public function taskControllerProvider(): array {
157 [CRM_Activity_Task
::TASK_DELETE
],
158 [CRM_Activity_Task
::TASK_PRINT
],
159 [CRM_Activity_Task
::TASK_EXPORT
],
160 [CRM_Activity_Task
::BATCH_UPDATE
],
161 [CRM_Activity_Task
::TASK_EMAIL
],
162 [CRM_Activity_Task
::PDF_LETTER
],
163 [CRM_Activity_Task
::TASK_SMS
],
164 [CRM_Activity_Task
::TAG_ADD
],
165 [CRM_Activity_Task
::TAG_REMOVE
],