From: Coleman Watts Date: Mon, 3 Jun 2013 22:40:29 +0000 (-0700) Subject: Fix and extend custom field options test CRM-12464 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=deceed83a3e5094e4c81b496ffead02ce2cf4824;p=civicrm-core.git Fix and extend custom field options test CRM-12464 ---------------------------------------- * CRM-12464: Add PseudoConstants to Schema Metadata http://issues.civicrm.org/jira/browse/CRM-12464 --- diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index eae36c04d0..b03e09fc1d 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -2167,6 +2167,8 @@ ORDER BY html_type"; } static function buildOption($field, &$options) { + // Fixme - adding anything but options to the $options array is a bad idea + // What if an option had the key 'attributes'? $options['attributes'] = array( 'label' => $field['label'], 'data_type' => $field['data_type'], diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index b8e56958b2..c32eb44840 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -229,7 +229,7 @@ class CRM_Core_PseudoConstant { $flip = !empty($params['flip']); // Custom fields are not in the schema - if (strpos($fieldName, 'custom') === 0) { + if (strpos($fieldName, 'custom') === 0 && is_numeric($fieldName[7])) { $dao = new CRM_Core_DAO_CustomField; $dao->id = (int) substr($fieldName, 7); $dao->find(TRUE); @@ -237,6 +237,8 @@ class CRM_Core_PseudoConstant { $dao->free(); $output = array(); CRM_Core_BAO_CustomField::buildOption($customField, $output); + // @see FIXME note in CRM_Core_BAO_CustomField::buildOption() + unset($output['attributes']); return $flip ? array_flip($output) : $output; } diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index 67b8a80848..146244f631 100644 --- a/tests/phpunit/CRM/Core/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php @@ -60,7 +60,27 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { $result = civicrm_api('customGroup', 'create', $api_params); $this->assertAPISuccess($result); - // Create a Group for testing. + // Add a custom field to the above field group. + $api_params = array( + 'version' => 3, + 'debug' => 1, + 'custom_group_id' => $result['id'], + 'label' => $custom_group_name, + 'html_type' => 'Select', + 'data_type' => 'String', + 'is_active' => TRUE, + 'option_values' => array(array( + 'label' => 'Foo', + 'value' => 'foo', + 'is_active' => 1, + 'weight' => 0, + )), + ); + $result = civicrm_api('custom_field', 'create', $api_params); + $this->assertAPISuccess($result); + $customFieldId = $result['id']; + + // Create a Contact Group for testing. $group_name = md5(microtime()); $api_params = array( 'version' => 3, @@ -417,6 +437,11 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { 'sample' => array('en_US' => 'English (United States)'), 'max' => 250, ), + array( + 'fieldName' => "custom_$customFieldId", + 'sample' => array('foo' => 'Foo'), + 'max' => 1, + ), ), 'CRM_Batch_DAO_Batch' => array( array(