From 52fa9e7ee6dbfbe08697bb394b478ddbe1ead8c9 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Mon, 28 Nov 2016 11:27:12 +0530 Subject: [PATCH] CRM-19680: Participant.get API generates invalid query when searching for role_id IS NULL --- CRM/Event/BAO/Query.php | 2 ++ tests/phpunit/api/v3/ParticipantTest.php | 38 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 4d3c728b66..ba13d92bf0 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -410,6 +410,8 @@ class CRM_Event_BAO_Query extends CRM_Core_BAO_Query { $qillName = $name; $name = 'role_id'; + $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; + $tableName = empty($tableName) ? 'civicrm_participant' : $tableName; if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { $op = key($value); $value = $value[$op]; diff --git a/tests/phpunit/api/v3/ParticipantTest.php b/tests/phpunit/api/v3/ParticipantTest.php index b46b253151..c5b0d837a6 100644 --- a/tests/phpunit/api/v3/ParticipantTest.php +++ b/tests/phpunit/api/v3/ParticipantTest.php @@ -98,6 +98,44 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { $this->quickCleanup($tablesToTruncate, TRUE); } + /** + * Test get participants with role_id. + */ + public function testGetParticipantWithRole() { + $roleId = array(1, 2, 3); + foreach ($roleId as $role) { + $this->participantCreate(array( + 'contact_id' => $this->individualCreate(), + 'role_id' => $role, + 'event_id' => $this->_eventID, + )); + } + + $params = array( + 'role_id' => 2, + ); + $result = $this->callAPISuccess('participant', 'get', $params); + //Assert all the returned participants has a role_id of 2 + foreach ($result['values'] as $pid => $values) { + $this->assertEquals($values['participant_role_id'], 2); + } + + $this->participantCreate(array( + 'id' => $this->_participantID, + 'role_id' => NULL, + 'event_id' => $this->_eventID, + )); + + $params['role_id'] = array( + 'IS NULL' => 1, + ); + $result = $this->callAPISuccess('participant', 'get', $params); + foreach ($result['values'] as $pid => $values) { + $this->assertEquals($values['participant_role_id'], NULL); + } + + } + /** * Check with complete array + custom field * Note that the test is written on purpose without any -- 2.25.1