From ae066a2bf45e519078da4ed103b5eeffc9a20a6b Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 16 Jan 2018 11:27:26 +1300 Subject: [PATCH] Add test for DB error on search add to group CRM-21159 I've also removed an unused parameter & a couple of require_once calls --- CRM/Contact/Form/Task.php | 4 +--- CRM/Contact/Selector.php | 3 +-- CRM/Contact/Selector/Custom.php | 2 +- tests/phpunit/CRM/Contact/SelectorTest.php | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index 0d33c818c9..853e1cb00e 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -298,11 +298,9 @@ class CRM_Contact_Form_Task extends CRM_Core_Form { } $selectorName = $this->controller->selectorName(); - require_once str_replace('_', DIRECTORY_SEPARATOR, $selectorName) . '.php'; $fv = $this->get('formValues'); $customClass = $this->get('customSearchClass'); - require_once 'CRM/Core/BAO/Mapping.php'; $returnProperties = CRM_Core_BAO_Mapping::returnProperties(self::$_searchFormValues); $selector = new $selectorName($customClass, $fv, NULL, $returnProperties); @@ -318,7 +316,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form { if (!$queryOperator) { $queryOperator = 'AND'; } - $dao = $selector->contactIDQuery($params, $this->_action, $sortID, + $dao = $selector->contactIDQuery($params, $sortID, CRM_Utils_Array::value('display_relationship_type', $fv), $queryOperator ); diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index a34e8a32f8..483d6e8349 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -1182,14 +1182,13 @@ SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', cont /** * @param array $params - * @param $action * @param int $sortID * @param null $displayRelationshipType * @param string $queryOperator * * @return CRM_Contact_DAO_Contact */ - public function contactIDQuery($params, $action, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') { + public function contactIDQuery($params, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') { $sortOrder = &$this->getSortOrder($this->_action); $sort = new CRM_Utils_Sort($sortOrder, $sortID); diff --git a/CRM/Contact/Selector/Custom.php b/CRM/Contact/Selector/Custom.php index b1cc490e88..628d13aaa5 100644 --- a/CRM/Contact/Selector/Custom.php +++ b/CRM/Contact/Selector/Custom.php @@ -424,7 +424,7 @@ class CRM_Contact_Selector_Custom extends CRM_Contact_Selector { * * @return Object */ - public function contactIDQuery($params, $action, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') { + public function contactIDQuery($params, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') { // $action, $displayRelationshipType and $queryOperator are unused. I have // no idea why they are there. diff --git a/tests/phpunit/CRM/Contact/SelectorTest.php b/tests/phpunit/CRM/Contact/SelectorTest.php index 6dca82988a..8aa95640b0 100644 --- a/tests/phpunit/CRM/Contact/SelectorTest.php +++ b/tests/phpunit/CRM/Contact/SelectorTest.php @@ -157,6 +157,22 @@ class CRM_Contact_Form_SelectorTest extends CiviUnitTestCase { ); } + /** + * Test the contact ID query does not fail on country search. + */ + public function testContactIDQuery() { + $params = [[ + 0 => 'country-1', + 1 => '=', + 2 => '1228', + 3 => 1, + 4 => 0, + ]]; + + $searchOBJ = new CRM_Contact_Selector(NULL); + $searchOBJ->contactIDQuery($params, '1_u'); + } + /** * Get the default select string since this is generally consistent. */ -- 2.25.1