CRM-19680: Participant.get API generates invalid query when searching for role_id...
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 28 Nov 2016 05:57:12 +0000 (11:27 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 28 Nov 2016 05:57:12 +0000 (11:27 +0530)
CRM/Event/BAO/Query.php
tests/phpunit/api/v3/ParticipantTest.php

index 4d3c728b66f777ce6cbe5a2b6d36a90fba8979ae..ba13d92bf0c27a30e25bee685f619b7402bb3b9e 100644 (file)
@@ -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];
index b46b253151e715bad34e7731348c9413d6a4bf8a..c5b0d837a6542f16e5ec793591f96278c4bfc789 100644 (file)
@@ -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