From: Seamus Lee <seamuslee001@gmail.com>
Date: Sun, 9 Dec 2018 02:28:55 +0000 (+1100)
Subject: Fix Locale Test by re-setting the locale used to en_US
X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9d65201d662cca092613fde6c22fdc2d0d436263;p=civicrm-core.git

Fix Locale Test by re-setting the locale used to en_US

Ensure that CRM_Core_I18n singleton is cleared as well
---

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'] = [];
   }
 
 }