From 1abf301c10069d81d5ab78ad6a0e6cd999ea9a8b Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Mon, 2 Mar 2020 18:43:09 -0500 Subject: [PATCH] Activity Details report: fix filtering by is null/is not null --- CRM/Report/Form/Activity.php | 2 +- tests/phpunit/api/v3/ReportTemplateTest.php | 25 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CRM/Report/Form/Activity.php b/CRM/Report/Form/Activity.php index fa43ee5f26..a0b619267e 100644 --- a/CRM/Report/Form/Activity.php +++ b/CRM/Report/Form/Activity.php @@ -544,7 +544,7 @@ class CRM_Report_Form_Activity extends CRM_Report_Form { } else { $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); - if ($op && ($op != 'nnll' && $op != 'nll')) { + if ($op && !($fieldName == "contact_{$recordType}" && ($op != 'nnll' || $op != 'nll'))) { $clause = $this->whereClause($field, $op, CRM_Utils_Array::value("{$fieldName}_value", $this->_params), diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 51d9e9956d..f4e999f9a2 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -1200,6 +1200,31 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $this->assertEquals($expected, $row); } + /** + * Activity Details report has some whack-a-mole to fix when filtering on null/not null. + */ + public function testActivityDetailsNullFilters() { + $this->createContactsWithActivities(); + $params = [ + 'report_id' => 'activity', + 'location_op' => 'nll', + 'location_value' => '', + ]; + $rowsWithoutLocation = $this->callAPISuccess('report_template', 'getrows', $params)['values']; + $this->assertEmpty($rowsWithoutLocation); + $params['location_op'] = 'nnll'; + $rowsWithLocation = $this->callAPISuccess('report_template', 'getrows', $params)['values']; + $this->assertCount(1, $rowsWithLocation); + // Test for CRM-18356 - activity shouldn't appear if target contact filter is null. + $params = [ + 'report_id' => 'activity', + 'contact_target_op' => 'nll', + 'contact_target_value' => '', + ]; + $rowsWithNullTarget = $this->callAPISuccess('report_template', 'getrows', $params)['values']; + $this->assertEmpty($rowsWithNullTarget); + } + /** * Set up some activity data..... use some chars that challenge our utf handling. */ -- 2.25.1