Commit a4c5e9a3 authored by colemanw's avatar colemanw

Fix custom option tests

parent 6d1902a6
......@@ -108,7 +108,7 @@ function civicrm_api3_generic_getfields($apiRequest) {
$helper($metadata);
}
$fieldsToResolve = CRM_Utils_Array::value('get_options', $apiOptions, array());
$fieldsToResolve = (array) CRM_Utils_Array::value('get_options', $apiOptions, array());
foreach ($metadata as $fieldname => $fieldSpec) {
_civicrm_api3_generic_get_metadata_options($metadata, $apiRequest['entity'], $fieldname, $fieldSpec, $fieldsToResolve);
......@@ -241,7 +241,7 @@ function _civicrm_api3_generic_get_metadata_options(&$metadata, $entity, $fieldn
$metadata[$fieldname]['api.aliases'][] = substr($fieldname, 0, -3);
}
if (!in_array($fieldname, $fieldsToResolve)) {
if (!empty($metadata[$fieldname]['options']) || !in_array($fieldname, $fieldsToResolve)) {
return;
}
......
......@@ -1322,10 +1322,12 @@ function _civicrm_api_get_custom_fields($entity, &$params) {
}
foreach ($customfields as $key => $value) {
// Regular fields have a 'name' property
$value['name'] = 'custom_' . $key;
$customfields['custom_' . $key] = $value;
if(in_array('custom_' . $key, $getoptions)){
$customfields['custom_' . $key]['options'] = CRM_Core_BAO_CustomOption::valuesByID($key);
}
if (in_array('custom_' . $key, $getoptions)) {
$customfields['custom_' . $key]['options'] = CRM_Core_BAO_CustomOption::valuesByID($key);
}
unset($customfields[$key]);
}
return $customfields;
......@@ -1568,6 +1570,12 @@ function _civicrm_api3_api_match_pseudoconstant_value(&$value, $options, $fieldN
return;
}
// Translate value into key
$newValue = array_search($value, $options);
if ($newValue !== FALSE) {
$value = $newValue;
return;
}
// Case-insensitive matching
$newValue = strtolower($value);
$options = array_map("strtolower", $options);
......@@ -1586,6 +1594,12 @@ function _civicrm_api3_api_match_pseudoconstant_value(&$value, $options, $fieldN
* @return (string|bool) fieldName or FALSE if the field does not exist
*/
function _civicrm_api3_api_resolve_alias($entity, $fieldName) {
if (strpos($fieldName, 'custom') === 0 && is_numeric($fieldName[7])) {
return $fieldName;
}
if ($fieldName == "{$entity}_id") {
return 'id';
}
$result = civicrm_api($entity, 'getfields', array(
'version' => 3,
'action' => 'create',
......@@ -1594,9 +1608,6 @@ function _civicrm_api3_api_resolve_alias($entity, $fieldName) {
if (isset($meta[$fieldName])) {
return $meta[$fieldName]['name'];
}
if ($fieldName == "{$entity}_id") {
return 'id';
}
foreach ($meta as $info) {
if ($fieldName == CRM_Utils_Array::value('uniqueName', $info)) {
return $info['name'];
......
......@@ -319,7 +319,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
// FIXME: look at it closer in second stage
// initialize the object once db is loaded
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton();
// when running unit tests, use mockup user framework
......
......@@ -341,7 +341,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
'version' => 3,
'action' => 'create',
);
$description = "Demonstrate retrieving custom field options";
$description = "Demonstrate retrieving metadata with custom field options";
$subfile = "GetFieldsOptions";
$fields = civicrm_api('contact', 'getfields', $getFieldsParams);
$this->documentMe($getFieldsParams, $fields, __FUNCTION__, 'ContactTest.php', $description,$subfile,'GetFields');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment