From: Coleman Watts Date: Fri, 7 Jun 2013 23:18:11 +0000 (-0700) Subject: Fix caching problem with tests X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8008547304aff4a74a75496194e3f43452129619;p=civicrm-core.git Fix caching problem with tests --- diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index c32eb44840..3d0366106b 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -488,9 +488,12 @@ class CRM_Core_PseudoConstant { * */ public static function flush($name = 'cache') { - if (isset(self::$name)) { + if (isset(self::$$name)) { self::$$name = NULL; } + if ($name == 'cache') { + CRM_Core_OptionGroup::flushAll(); + } } /** diff --git a/api/v3/utils.php b/api/v3/utils.php index 54f0d378ec..6748651257 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1567,16 +1567,15 @@ function _civicrm_api3_api_match_pseudoconstant_value(&$value, $options, $fieldN if (isset($options[$value])) { return; } - // Generate error msg before overwriting the value - $errorMsg = "'$value' is not a valid option for field $fieldName"; // Case-insensitive matching - $value = strtolower($value); + $newValue = strtolower($value); $options = array_map("strtolower", $options); - $value = array_search($value, $options); - if ($value === FALSE) { - throw new API_Exception($errorMsg, 2001, array('error_field' => $fieldName)); + $newValue = array_search($newValue, $options); + if ($newValue === FALSE) { + throw new API_Exception("'$value' is not a valid option for field $fieldName", 2001, array('error_field' => $fieldName)); } + $value = $newValue; } /** diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 22fee9a65d..d6cc15a539 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -1441,7 +1441,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { ); } - require_once 'CRM/Core/DAO/LocationType.php'; $locationType = new CRM_Core_DAO_LocationType(); $locationType->copyValues($params); $locationType->save(); @@ -1794,7 +1793,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } $customGroup = $this->CustomGroupCreate($entity, $function); $customField = $this->customFieldCreate($customGroup['id'], $function); - CRM_Core_PseudoConstant::flush('customGroup'); + CRM_Core_PseudoConstant::flush(); return array('custom_group_id' => $customGroup['id'], 'custom_field_id' => $customField['id']); } diff --git a/tests/phpunit/api/v3/CustomValueContactTypeTest.php b/tests/phpunit/api/v3/CustomValueContactTypeTest.php index 6784c247d5..b80fec3848 100644 --- a/tests/phpunit/api/v3/CustomValueContactTypeTest.php +++ b/tests/phpunit/api/v3/CustomValueContactTypeTest.php @@ -120,7 +120,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { ); $this->organizationSponsor = $this->organizationCreate($params); //refresh php cached variables - CRM_Core_PseudoConstant::flush('customGroup'); + CRM_Core_PseudoConstant::flush(); CRM_Core_BAO_CustomField::getTableColumnGroup($this->IndividualField['id'], True); CRM_Core_BAO_CustomField::getTableColumnGroup($this->IndiStudentField['id'], True); }