Fix caching problem with tests
authorColeman Watts <coleman@civicrm.org>
Fri, 7 Jun 2013 23:18:11 +0000 (16:18 -0700)
committerColeman Watts <coleman@civicrm.org>
Fri, 7 Jun 2013 23:18:11 +0000 (16:18 -0700)
CRM/Core/PseudoConstant.php
api/v3/utils.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/CustomValueContactTypeTest.php

index c32eb44840ac13c032f9c735c0f95a4ae969d473..3d0366106b12e40bf02e5fe5ee23d37afb9cc3b4 100644 (file)
@@ -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();
+    }
   }
 
   /**
index 54f0d378ecabeb04fd7b0761ca5b08790dd07130..6748651257218dff0cd4db42aa0663dc27e01544 100644 (file)
@@ -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;
 }
 
 /**
index 22fee9a65de1a4e013353a508c3334a8921ea4eb..d6cc15a5391c34a6e9578d5db7747e7a6efd3740 100644 (file)
@@ -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']);
   }
index 6784c247d573ded74c7a040c3f086f6504a3c46e..b80fec3848ae0746561a6d9d89ea6dda4758d8d8 100644 (file)
@@ -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);
   }