Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21135 - Activity filter preference are not remembered when enable… #10932

Merged
merged 1 commit into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions CRM/Activity/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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;
}
Expand All @@ -446,7 +449,7 @@ public static function getContactActivity() {
}
}
elseif (in_array($searchField, array('activity_type_id', 'activity_type_exclude_id'))) {
$activityFilter[$searchField] = '';
$activityFilter[$formSearchField] = '';
}
}

Expand All @@ -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);
}
Expand Down
19 changes: 14 additions & 5 deletions tests/phpunit/CRM/Activity/BAO/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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']);
}
}

Expand Down