4 * Include dataProvider for tests
7 class CRM_Activity_Form_SearchTest
extends CiviUnitTestCase
{
9 public function setUp() {
11 $this->individualID
= $this->individualCreate();
12 $this->contributionCreate([
13 'contact_id' => $this->individualID
,
14 'receive_date' => '2017-01-30',
18 public function tearDown() {
21 'civicrm_activity_contact',
23 $this->quickCleanup($tablesToTruncate);
27 * Test submitted the search form.
29 public function testSearch() {
31 $form = new CRM_Activity_Form_Search();
32 $_SERVER['REQUEST_METHOD'] = 'GET';
33 $form->controller
= new CRM_Activity_Controller_Search();
36 $qfKey = $form->controller
->_key
;
37 $rows = $form->controller
->get('rows');
41 'contact_type' => '<a href="/index.php?q=civicrm/profile/view&reset=1&gid=7&id=3&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',
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',
59 '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>',
61 'campaign_id' => NULL,
68 * Test the Qill for activity Date time.
70 * @dataProvider getSearchCriteria
72 * @param array $searchCriteria
73 * @param array $expectedQill
75 public function testQill($searchCriteria, $expectedQill) {
76 $selector = new CRM_Activity_Selector_Search($searchCriteria);
77 $this->assertEquals($expectedQill, $selector->getQILL());
81 * Get criteria for activity testing.
83 public function getSearchCriteria() {
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);
93 'search_criteria' => [
94 ['activity_date_time_relative', '=', 'ending_60.day', 0, 0],
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) . ')']],
99 'search_criteria' => [
100 ['activity_date_time_relative', '=', 'earlier.year', 0, 0],
102 'expected_qill' => [['Activity Date is To end of previous calendar year (to ' . CRM_Utils_Date
::customFormat($dates['earlier.year'][1], $format) . ')']],
105 'search_criteria' => [
106 ['activity_date_time_relative', '=', 'greater.year', 0, 0],
108 'expected_qill' => [['Activity Date is From start of current calendar year (from ' . CRM_Utils_Date
::customFormat($dates['greater.year'][0], $format) . ')']],
111 'search_criteria' => [
112 ['activity_date_time_low', '=', '2019-03-05', 0, 0],
113 ['activity_date_time_high', '=', '2019-03-27', 0, 0],
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"']],
118 'search_criteria' => [
119 ['activity_status_id', '=', ['IN' => ['1', '2']], 0, 0],
121 'expected_qill' => [['Activity Status In Scheduled, Completed']],