From 96dc1ce0e4268e946dc9d72147cbebae57205621 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Wed, 2 Sep 2015 15:43:41 +1200 Subject: [PATCH] CRM-17120 replace option label calls with cached function. I added a test before swapping out the values. In the process I formed a few doubts about the code. I couldn't find anyway to access the case_activity where parameters outside a carefully crafted test and when I did so I got invalid sql & a minor error in the qill I added comments about these findings & locked in the existing behaviour, keeping this change very safe --- CRM/Case/BAO/Query.php | 18 +++++-- tests/phpunit/CRM/Case/BAO/QueryTest.php | 68 ++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/CRM/Case/BAO/QueryTest.php diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php index da243165ea..273e6e5556 100644 --- a/CRM/Case/BAO/Query.php +++ b/CRM/Case/BAO/Query.php @@ -237,6 +237,16 @@ class CRM_Case_BAO_Query { /** * Where clause for a single field. * + * CRM-17120 adds a test that checks the Qill on some of these parameters. + * However, I couldn't find a way, other than via test, to access the + * case_activity options in the code below and invalid sql was returned. + * Perhaps the options are just legacy? + * + * Also, CRM-17120 locks in the Qill - but it probably is not quite right as I + * see 'Activity Type = Scheduled' (rather than activity status). + * + * See CRM_Case_BAO_QueryTest for more. + * * @param array $values * @param CRM_Contact_BAO_Query $query */ @@ -348,7 +358,7 @@ class CRM_Case_BAO_Query { case 'case_recent_activity_type': $names = $value; - if ($activityType = CRM_Core_OptionGroup::getLabel('activity_type', $value, 'value')) { + if (($activityType = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'activity_type_id', $value)) != FALSE) { $names = $activityType; } @@ -361,8 +371,10 @@ class CRM_Case_BAO_Query { return; case 'case_activity_status_id': + echo $value; + $names = $value; - if ($activityStatus = CRM_Core_OptionGroup::getLabel('activity_status', $value, 'value')) { + if (($activityStatus = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'status_id', $value)) != FALSE) { $names = $activityStatus; } @@ -384,7 +396,7 @@ class CRM_Case_BAO_Query { case 'case_activity_medium_id': $names = $value; - if ($activityMedium = CRM_Core_OptionGroup::getLabel('encounter_medium', $value, 'value')) { + if (($activityMedium = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'medium_id', $value)) != FALSE) { $names = $activityMedium; } diff --git a/tests/phpunit/CRM/Case/BAO/QueryTest.php b/tests/phpunit/CRM/Case/BAO/QueryTest.php new file mode 100644 index 0000000000..828b534654 --- /dev/null +++ b/tests/phpunit/CRM/Case/BAO/QueryTest.php @@ -0,0 +1,68 @@ + array( + 0 => 'case_recent_activity_type', + 1 => '=', + 2 => 6, + 3 => 1, + 4 => 0, + ), + 1 => array( + 0 => 'case_activity_status_id', + 1 => '=', + 2 => 1, + 3 => 1, + 4 => 0, + ), + 2 => array( + 0 => 'case_activity_medium_id', + 1 => '=', + 2 => 1, + 3 => 1, + 4 => 0, + ), + ); + + $queryObj = new CRM_Contact_BAO_Query($params, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CASE); + $this->assertEquals(array( + 0 => 'Activity Type = Contribution', + 1 => 'Activity Type = Scheduled', + 2 => 'Activity Medium = In Person', + ), + $queryObj->_qill[1] + ); + } +} -- 2.25.1