From 08fe8c7e5b573b8fb2387c129d947ae47e58686c Mon Sep 17 00:00:00 2001 From: monishdeb Date: Tue, 30 Dec 2014 21:01:22 +0530 Subject: [PATCH] Api test failures fix round2 --- CRM/Contribute/BAO/Query.php | 6 ++++++ api/v3/utils.php | 12 +++++++++++- tests/phpunit/api/v3/SyntaxConformanceTest.php | 6 ++++++ tests/phpunit/api/v3/UFGroupTest.php | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index cd48798018..dd80019691 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -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"; diff --git a/api/v3/utils.php b/api/v3/utils.php index d06d622e1f..7de10af76d 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -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; } diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index f1e8c5f493..049de1efd5 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -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']); } diff --git a/tests/phpunit/api/v3/UFGroupTest.php b/tests/phpunit/api/v3/UFGroupTest.php index 4e77db76af..52b3172255 100644 --- a/tests/phpunit/api/v3/UFGroupTest.php +++ b/tests/phpunit/api/v3/UFGroupTest.php @@ -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, -- 2.25.1