From ddfe0227c4c338c95157da434ac6c2703d1c6b63 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Wed, 16 Jun 2021 11:54:19 -0400 Subject: [PATCH] unable to remove a currency once added --- CRM/Core/OptionGroup.php | 9 ++++-- .../Admin/Form/Setting/LocalizationTest.php | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/CRM/Admin/Form/Setting/LocalizationTest.php diff --git a/CRM/Core/OptionGroup.php b/CRM/Core/OptionGroup.php index 727f2b2214..1843cfeeb9 100644 --- a/CRM/Core/OptionGroup.php +++ b/CRM/Core/OptionGroup.php @@ -466,6 +466,12 @@ WHERE v.option_group_id = g.id * the option group ID */ public static function createAssoc($groupName, &$values, &$defaultID, $groupTitle = NULL) { + // @TODO: This causes a problem in multilingual + // (https://github.com/civicrm/civicrm-core/pull/17228), but is needed in + // order to be able to remove currencies once added. + if (!CRM_Core_I18n::isMultiLingual()) { + self::deleteAssoc($groupName); + } if (!empty($values)) { $group = new CRM_Core_DAO_OptionGroup(); $group->name = $groupName; @@ -552,11 +558,8 @@ ORDER BY v.weight /** * @param string $groupName * @param string $operator - * - * @deprecated */ public static function deleteAssoc($groupName, $operator = "=") { - CRM_Core_Error::deprecatedFunctionWarning('unused function'); $query = " DELETE g, v FROM civicrm_option_group g, diff --git a/tests/phpunit/CRM/Admin/Form/Setting/LocalizationTest.php b/tests/phpunit/CRM/Admin/Form/Setting/LocalizationTest.php new file mode 100644 index 0000000000..d92baf18f2 --- /dev/null +++ b/tests/phpunit/CRM/Admin/Form/Setting/LocalizationTest.php @@ -0,0 +1,28 @@ +assertEquals(['CAD', 'USD'], $currencies, 'Unable to add a currency.'); + + // Now try to remove it. + CRM_Admin_Form_Setting_Localization::updateEnabledCurrencies(['USD'], 'USD'); + CRM_Core_OptionGroup::flushAll(); + $currencies = array_keys(CRM_Core_OptionGroup::values('currencies_enabled')); + $this->assertEquals(['USD'], $currencies, 'Unable to remove a currency.'); + + // Note in the form there's code to prevent removing the default. The + // function we're testing here isn't the full form so we're not testing + // that. + } + +} -- 2.25.1