From c3a9ccbb2f76fe3f8cf61d3cf5183b7e5e975f70 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Fri, 1 Sep 2017 16:23:17 +0530 Subject: [PATCH] CRM-21135 - Activity filter preference are not remembered when enabled in display settings --- CRM/Activity/Page/AJAX.php | 18 ++++++++++++------ .../phpunit/CRM/Activity/BAO/ActivityTest.php | 19 ++++++++++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index a7fab121825e..1c3203cea7c7 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -420,10 +420,6 @@ public static function getContactActivity() { // get the contact activities $activities = CRM_Activity_BAO_Activity::getContactActivitySelector($params); - if (!empty($_GET['is_unit_test'])) { - return $activities; - } - foreach ($activities['data'] as $key => $value) { // Check if recurring activity. if (!empty($value['is_recurring_activity'])) { @@ -436,8 +432,15 @@ public static function getContactActivity() { if (Civi::settings()->get('preserve_activity_tab_filter') && ($userID = CRM_Core_Session::getLoggedInContactID())) { unset($optionalParameters['context']); foreach ($optionalParameters as $searchField => $dataType) { + $formSearchField = $searchField; + if ($searchField == 'activity_type_id') { + $formSearchField = 'activity_type_filter_id'; + } + elseif ($searchField == 'activity_type_exclude_id') { + $formSearchField = 'activity_type_exclude_filter_id'; + } if (!empty($params[$searchField])) { - $activityFilter[$searchField] = CRM_Utils_Type::escape($params[$searchField], $dataType); + $activityFilter[$formSearchField] = CRM_Utils_Type::escape($params[$searchField], $dataType); if (in_array($searchField, array('activity_date_low', 'activity_date_high'))) { $activityFilter['activity_date_relative'] = 0; } @@ -446,7 +449,7 @@ public static function getContactActivity() { } } elseif (in_array($searchField, array('activity_type_id', 'activity_type_exclude_id'))) { - $activityFilter[$searchField] = ''; + $activityFilter[$formSearchField] = ''; } } @@ -456,6 +459,9 @@ public static function getContactActivity() { $cSettings = Civi::service('settings_manager')->getBagByContact(CRM_Core_Config::domainID(), $userID); $cSettings->set('activity_tab_filter', $activityFilter); } + if (!empty($_GET['is_unit_test'])) { + return array($activities, $activityFilter); + } CRM_Utils_JSON::output($activities); } diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index 27089d025434..30cd60fbdfe0 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -364,6 +364,8 @@ public function testActivityFilters() { dirname(__FILE__) . '/activities_for_dashboard_count.xml' ) ); + Civi::settings()->set('preserve_activity_tab_filter', 1); + $this->createLoggedInUser(); global $_GET; $_GET = array( @@ -372,20 +374,27 @@ public function testActivityFilters() { 'activity_type_id' => 1, 'is_unit_test' => 1, ); - $obj = new CRM_Activity_Page_AJAX(); + $expectedFilters = array( + 'activity_type_filter_id' => 1, + 'activity_type_exclude_filter_id' => '', + ); - $activities = $obj->getContactActivity(); + list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity(); + //Assert whether filters are correctly set. + $this->checkArrayEquals($expectedFilters, $activityFilter); // This should include activities of type Meeting only. foreach ($activities['data'] as $value) { $this->assertContains('Meeting', $value['activity_type']); } unset($_GET['activity_type_id']); + $expectedFilters['activity_type_filter_id'] = ''; - $_GET['activity_type_exclude_id'] = 1; - $activities = $obj->getContactActivity(); + $_GET['activity_type_exclude_id'] = $expectedFilters['activity_type_exclude_filter_id'] = 1; + list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity(); + $this->checkArrayEquals($expectedFilters, $activityFilter); // None of the activities should be of type Meeting. foreach ($activities['data'] as $value) { - $this->assertNotEquals('Meeting', $value['activity_type']); + $this->assertNotContains('Meeting', $value['activity_type']); } }