From a4a3348656e9bd55d1ba0b0ab886e1c64501ace6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 13 Jun 2013 14:25:40 -0700 Subject: [PATCH] More caching fixes for tests --- CRM/Core/BAO/OptionValue.php | 2 ++ CRM/Core/OptionGroup.php | 1 + api/v3/Generic.php | 1 + tests/phpunit/api/v3/OptionValueTest.php | 41 ++++++++++-------------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/CRM/Core/BAO/OptionValue.php b/CRM/Core/BAO/OptionValue.php index 1aba33a618..5cb69324e2 100644 --- a/CRM/Core/BAO/OptionValue.php +++ b/CRM/Core/BAO/OptionValue.php @@ -204,6 +204,7 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue { $optionValue->id = CRM_Utils_Array::value('optionValue', $ids); $optionValue->save(); + CRM_Core_PseudoConstant::flush(); return $optionValue; } @@ -221,6 +222,7 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->id = $optionValueId; if (self::updateRecords($optionValueId, CRM_Core_Action::DELETE)) { + CRM_Core_PseudoConstant::flush(); return $optionValue->delete(); } return FALSE; diff --git a/CRM/Core/OptionGroup.php b/CRM/Core/OptionGroup.php index 33251b38ac..9a9c9bb8ca 100644 --- a/CRM/Core/OptionGroup.php +++ b/CRM/Core/OptionGroup.php @@ -596,6 +596,7 @@ WHERE v.option_group_id = g.id static function flushAll() { self::$_values = array(); self::$_cache = array(); + CRM_Utils_Cache::singleton()->flush(); } } diff --git a/api/v3/Generic.php b/api/v3/Generic.php index 1e17e92079..050a077ca8 100644 --- a/api/v3/Generic.php +++ b/api/v3/Generic.php @@ -213,6 +213,7 @@ function civicrm_api3_generic_getoptions($apiRequest) { if (!$fieldName) { return civicrm_api3_create_error("The field '{$apiRequest['params']['field']}' doesn't exist."); } + // Validate 'context' from params $context = CRM_Utils_Array::value('context', $apiRequest['params']); CRM_Core_DAO::buildOptionsContext($context); diff --git a/tests/phpunit/api/v3/OptionValueTest.php b/tests/phpunit/api/v3/OptionValueTest.php index 4e771d4b1e..1710c5be14 100644 --- a/tests/phpunit/api/v3/OptionValueTest.php +++ b/tests/phpunit/api/v3/OptionValueTest.php @@ -266,37 +266,30 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { $this->assertAPISuccess($optionValue); $this->getAndCheck($params, $optionValue['id'], 'option_value'); } - /* + + /** * Check that pseudoconstant reflects new value added - * and deleted - */ + * and deleted + */ public function testCRM11876CreateOptionPseudoConstantUpdated() { $optionGroupID = civicrm_api('option_group', 'getvalue', array( 'version' => $this->_apiversion, 'name' => 'payment_instrument', - 'return' => 'id',) - ); - $apiResult = civicrm_api('option_value', 'create', array( - 'option_group_id' => $optionGroupID, - 'label' => 'newest', - 'version' => $this->_apiversion, + 'return' => 'id', + )); + $newOption = (string) time(); + $apiResult = $this->callAPISuccess('option_value', 'create', array( + 'option_group_id' => $optionGroupID, + 'label' => $newOption, )); - $this->assertAPISuccess($apiResult); - $fields = civicrm_api('contribution', 'getoptions', array( - 'version' => $this->_apiversion, - 'field' => 'payment_instrument', - ) - ); - $this->assertTrue(in_array('newest', $fields['values'])); - $deleteResult = civicrm_api('option_value', 'delete', array('id' => $apiResult['id'], 'version' => $this->_apiversion)); - $this->assertAPISuccess($deleteResult); - $fields = civicrm_api('contribution', 'getoptions', array( - 'version' => $this->_apiversion, - 'field' => 'payment_instrument', - ) - ); - $this->assertFalse(in_array('newest', $fields['values'])); + $fields = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); + $this->assertTrue(in_array($newOption, $fields['values'])); + + $this->callAPISuccess('option_value', 'delete', array('id' => $apiResult['id'])); + + $fields = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); + $this->assertFalse(in_array($newOption, $fields['values'])); } } -- 2.25.1