Fix Locale Test by re-setting the locale used to en_US
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 9 Dec 2018 02:28:55 +0000 (13:28 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Sun, 9 Dec 2018 07:29:48 +0000 (18:29 +1100)
Ensure that CRM_Core_I18n singleton is cleared as well

CRM/Core/I18n.php
tests/phpunit/CRM/Core/I18n/LocaleTest.php

index 6dfbe23b566c30388fbd1ab89c46543b298c403c..62f339f0a7beddad45490c082721bf32697a6b6c 100644 (file)
@@ -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];
   }
 
   /**
index cb1e88fb6f0cb8de0b8b7e8be6dd5e6c21583b23..320f193f6c3fe90140f96b3434837947de0d57e9 100644 (file)
@@ -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'] = [];
   }
 
 }