From 3d3ef91862f09ee0dd75caea12fd20a097606429 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 17 Jun 2013 15:43:27 -0700 Subject: [PATCH] Fix SyntaxConformanceTest and EnumValues --- CRM/Contact/BAO/Contact.php | 2 +- CRM/Core/BAO/Address.php | 2 +- CRM/Core/DAO.php | 2 +- CRM/Core/PseudoConstant.php | 2 +- CRM/Financial/BAO/PaymentProcessorType.php | 2 +- .../v3/SyntaxConformanceAllEntitiesTest.php | 18 +++++++----------- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index ea9238937b..8cb9d9c2fe 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2998,7 +2998,7 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) * TODO: In context of chainselect, what to return if e.g. a country has no states? * * @param String $fieldName - * @param String $context: e.g. "search" "edit" "create" "view" + * @param String $context: @see CRM_Core_DAO::buildOptionsContext * @param Array $props: whatever is known about this dao object */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 53131f3ee8..2c9c3259fc 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -1158,7 +1158,7 @@ SELECT is_primary, * TODO: In context of chainselect, what to return if e.g. a country has no states? * * @param String $fieldName - * @param String $context: e.g. "search" "edit" "create" "view" + * @param String $context: @see CRM_Core_DAO::buildOptionsContext * @param Array $props: whatever is known about this dao object */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index c79489ec1f..bc642752be 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1764,7 +1764,7 @@ EOS; * The overriding function will generally call the lower-level CRM_Core_PseudoConstant::get * * @param String $fieldName - * @param String $context: e.g. "search" "get" "create" "validate" + * @param String $context: @see CRM_Core_DAO::buildOptionsContext * @param Array $props: whatever is known about this bao object */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 53c1e63bcd..e5a0c27091 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -272,7 +272,7 @@ class CRM_Core_PseudoConstant { // use of a space after the comma is inconsistent in xml $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']); $output = explode(',', $enumStr); - return $flip ? array_flip($output) : $output; + return array_combine($output, $output); } elseif (!empty($fieldSpec['pseudoconstant'])) { diff --git a/CRM/Financial/BAO/PaymentProcessorType.php b/CRM/Financial/BAO/PaymentProcessorType.php index ee789920db..0a0b420680 100644 --- a/CRM/Financial/BAO/PaymentProcessorType.php +++ b/CRM/Financial/BAO/PaymentProcessorType.php @@ -219,7 +219,7 @@ WHERE pp.payment_processor_type_id = ppt.id AND ppt.id = %1"; * @see CRM_Core_DAO::buildOptions * * @param String $fieldName - * @param String $context: e.g. "search" "edit" "create" "view" + * @param String $context: @see CRM_Core_DAO::buildOptionsContext * @param Array $props: whatever is known about this dao object */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { diff --git a/tests/phpunit/api/v3/SyntaxConformanceAllEntitiesTest.php b/tests/phpunit/api/v3/SyntaxConformanceAllEntitiesTest.php index cac59c7e5c..18824f20cd 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceAllEntitiesTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceAllEntitiesTest.php @@ -704,16 +704,12 @@ class api_v3_SyntaxConformanceAllEntitiesTest extends CiviUnitTestCase { case CRM_Utils_Type::T_URL: $entity[$field] = 'warm.beer.com'; } - $constant = CRM_Utils_Array::value('pseudoconstant', $specs); - if (!empty($constant)) { - $constantOptions = array_reverse(array_keys(CRM_Utils_PseudoConstant::getConstant($constant['name']))); - $entity[$field] = (string) $constantOptions[0]; - } - $enum = CRM_Utils_Array::value('enumValues', $specs); - if (!empty($enum)) { - // reverse so we 'change' value - $options = array_reverse(explode(',', $enum)); - $entity[$fieldName] = $options[0]; + if (!empty($specs['pseudoconstant']) || !empty($specs['enumValues'])) { + $options = civicrm_api($entityName, 'getoptions', array('context' => 'create', 'field' => $field, 'version' => 3)); + if (empty($options['values'])) { + print_r($options); + } + $entity[$field] = array_rand($options['values']); } $updateParams = array( 'version' => 3, @@ -738,7 +734,7 @@ class api_v3_SyntaxConformanceAllEntitiesTest extends CiviUnitTestCase { ); $checkEntity = civicrm_api($entityName, 'getsingle', $checkParams); - $this->assertEquals($entity, $checkEntity, "changing field $fieldName" . print_r($entity,TRUE) );//. print_r($checkEntity,true) .print_r($checkParams,true) . print_r($update,true) . print_r($updateParams, TRUE)); + $this->assertEquals($entity, $checkEntity, "changing field $fieldName\n" . print_r($entity,TRUE) );//. print_r($checkEntity,true) .print_r($checkParams,true) . print_r($update,true) . print_r($updateParams, TRUE)); } $baoObj->deleteTestObjects($baoString); $baoObj->free(); -- 2.25.1