From 9d65201d662cca092613fde6c22fdc2d0d436263 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 9 Dec 2018 13:28:55 +1100 Subject: [PATCH] Fix Locale Test by re-setting the locale used to en_US Ensure that CRM_Core_I18n singleton is cleared as well --- CRM/Core/I18n.php | 11 ++++++----- tests/phpunit/CRM/Core/I18n/LocaleTest.php | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index 6dfbe23b56..62f339f0a7 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -660,14 +660,15 @@ class CRM_Core_I18n { * @return CRM_Core_I18n */ public static function &singleton() { - static $singleton = array(); - + if (!isset(Civi::$statics[__CLASS__]['singleton'])) { + Civi::$statics[__CLASS__]['singleton'] = array(); + } $tsLocale = CRM_Core_I18n::getLocale(); - if (!isset($singleton[$tsLocale])) { - $singleton[$tsLocale] = new CRM_Core_I18n($tsLocale); + if (!isset(Civi::$statics[__CLASS__]['singleton'][$tsLocale])) { + Civi::$statics[__CLASS__]['singleton'][$tsLocale] = new CRM_Core_I18n($tsLocale); } - return $singleton[$tsLocale]; + return Civi::$statics[__CLASS__]['singleton'][$tsLocale]; } /** diff --git a/tests/phpunit/CRM/Core/I18n/LocaleTest.php b/tests/phpunit/CRM/Core/I18n/LocaleTest.php index cb1e88fb6f..320f193f6c 100644 --- a/tests/phpunit/CRM/Core/I18n/LocaleTest.php +++ b/tests/phpunit/CRM/Core/I18n/LocaleTest.php @@ -50,6 +50,8 @@ class CRM_Core_I18n_LocaleTest extends CiviUnitTestCase { $locale = CRM_Core_I18n::getLocale(); $this->assertEquals($locale, 'fr_CA'); + CRM_Core_I18n::singleton()->setLocale('en_US'); + Civi::$statics['CRM_Core_I18n']['singleton'] = []; } } -- 2.25.1