Api test failures fix round2
authormonishdeb <monish.deb@webaccessglobal.com>
Tue, 30 Dec 2014 15:31:22 +0000 (21:01 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Wed, 28 Jan 2015 07:46:24 +0000 (13:16 +0530)
CRM/Contribute/BAO/Query.php
api/v3/utils.php
tests/phpunit/api/v3/SyntaxConformanceTest.php
tests/phpunit/api/v3/UFGroupTest.php

index cd48798018ec5c13c85d2df609d70a51279a96ff..dd80019691b3b9cf8d0210122acd58f59c9a4ffb 100644 (file)
@@ -108,6 +108,12 @@ class CRM_Contribute_BAO_Query {
       $query->_tables['contribution_batch'] = 1;
     }
 
+    if (!empty($query->_returnProperties['contribution_source'])) {
+      $query->_select['contribution_source'] = "civicrm_contribution.source as contribution_source";
+      $query->_element['contribution_source'] = 1;
+      $query->_tables['civicrm_contribution'] = 1;
+    }
+
     // get contribution_status
     if (!empty($query->_returnProperties['contribution_status_id'])) {
       $query->_select['contribution_status_id'] = "contribution_status.value as contribution_status_id";
index d06d622e1fcccbfca02ef26c8a7287dc746b29b4..7de10af76d926d25a8b865e6bdae099b78b1836d 100644 (file)
@@ -1848,6 +1848,7 @@ function _civicrm_api3_validate_integer(&$params, &$fieldName, &$fieldInfo, $ent
         2100, array('field' => $fieldName, "max_length"=>$fieldInfo['maxlength'])
       );
     }
+    $params[$fieldName] = $fieldValue;
   }
 }
 
@@ -1969,6 +1970,8 @@ function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $enti
  */
 function _civicrm_api3_api_match_pseudoconstant(&$fieldValue, $entity, $fieldName, $fieldInfo) {
   $options = CRM_Utils_Array::value('options', $fieldInfo);
+  $pseudoconstant = CRM_Utils_Array::value('pseudoconstant', $fieldInfo);
+
   if (!$options) {
     if (strtolower($entity) == 'profile' && !empty($fieldInfo['entity'])) {
       // we need to get the options from the entity the field relates to
@@ -1976,6 +1979,12 @@ function _civicrm_api3_api_match_pseudoconstant(&$fieldValue, $entity, $fieldNam
     }
     $options = civicrm_api($entity, 'getoptions', array('version' => 3, 'field' => $fieldInfo['name'], 'context' => 'validate'));
     $options = CRM_Utils_Array::value('values', $options, array());
+
+    if (count($options) == 0 && isset($pseudoconstant['table'])) {
+        $pseudoParams = $pseudoconstant;
+        unset($pseudoParams['table']);
+        $options = CRM_Core_PseudoConstant::get(CRM_Core_DAO_AllCoreTables::getClassForTable($pseudoconstant['table']), $fieldName, $pseudoParams);
+    }
   }
 
   // If passed a value-separated string, explode to an array, then re-implode after matching values
@@ -2013,7 +2022,8 @@ function _civicrm_api3_api_match_pseudoconstant(&$fieldValue, $entity, $fieldNam
  */
 function _civicrm_api3_api_match_pseudoconstant_value(&$value, $options, $fieldName) {
   // If option is a key, no need to translate
-  if (array_key_exists($value, $options)) {
+  // or if no options are avaiable for pseudoconstant 'table' property
+  if (array_key_exists($value, $options) || !$options) {
     return;
   }
 
index f1e8c5f49358b4d6e881d0f25f1b1eca7471a6de..049de1efd54df6e7d571a4ab0275508396b930b4 100644 (file)
@@ -1138,6 +1138,12 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
               ));
             $options['values'][] = $optionValue['id'];
           }
+          if (isset($specs['pseudoconstant']['table'])) {
+            //some psedoconstant property is based on other entity attributes
+            //as the there may or maynot be records for such entity, so we are considering empty records for now
+            //e.g. pcp_id property will be table=civicrm_pcp, keyColumn=id and labelColumn=title
+            continue;
+          }
         }
         $entity[$field] = array_rand($options['values']);
       }
index 4e77db76af2f8313cfcbb334e3d8862a16bc716c..52b31722555c76ad8dd8a94f3d5443ce627567cc 100644 (file)
@@ -58,7 +58,7 @@ class api_v3_UFGroupTest extends CiviUnitTestCase {
       'uf_id' => 42,
       'uf_name' => 'email@mail.com',
     ));
-    $this->_ufGroupId = $ufMatch['id'];
+    $this->_ufMatchId = $ufMatch['id'];
     $this->params = array(
       'add_captcha' => 1,
       'add_contact_to_group' => $this->_groupId,