3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 * Class CRM_Core_I18n_LocaleTest
31 class CRM_Core_I18n_LocaleTest
extends CiviUnitTestCase
{
33 public function setUp() {
37 public function tearDown() {
44 public function testI18nLocaleChange() {
45 $this->enableMultilingual();
46 CRM_Core_I18n_Schema
::addLocale('fr_CA', 'en_US');
48 CRM_Core_I18n
::singleton()->setLocale('fr_CA');
49 $locale = CRM_Core_I18n
::getLocale();
51 $this->assertEquals($locale, 'fr_CA');
53 CRM_Core_I18n
::singleton()->setLocale('en_US');
54 CRM_Core_I18n_Schema
::makeSinglelingual('en_US');
55 Civi
::$statics['CRM_Core_I18n']['singleton'] = [];
58 public function testUiLanguages() {
60 'en_US' => 'English (United States)',
61 'fr_CA' => 'French (Canada)',
64 $codes = array_keys($languages);
65 Civi
::settings()->set('uiLanguages', $codes);
67 // Check we can retrieve the setting
68 $result = Civi
::settings()->get('uiLanguages');
69 $this->assertEquals($codes, $result);
72 $result = CRM_Core_I18n
::uiLanguages(TRUE);
73 $this->assertArrayValuesEqual($codes, $result);
75 // Monolingual, codes and language labels
76 $result = CRM_Core_I18n
::uiLanguages();
77 $this->assertTreeEquals($languages, $result);
79 $this->enableMultilingual();
81 CRM_Core_I18n_Schema
::addLocale('fr_CA', 'en_US');
82 // Make fr_CA 'available'
83 Civi
::settings()->set('languageLimit', ['en_US' => 1, 'fr_CA' => 1]);
85 // Multilingual, codes
86 $result = CRM_Core_I18n
::uiLanguages(TRUE);
87 $this->assertArrayValuesEqual(['en_US', 'fr_CA'], $result);
89 // Multilingual, codes and language labels
90 $result = CRM_Core_I18n
::uiLanguages();
91 $this->assertTreeEquals([
92 'en_US' => 'English (United States)',
93 'fr_CA' => 'French (Canada)',
96 CRM_Core_I18n
::singleton()->setLocale('en_US');
97 CRM_Core_I18n_Schema
::makeSinglelingual('en_US');
98 Civi
::$statics['CRM_Core_I18n']['singleton'] = [];