Merge pull request #12669 from eileenmcnaughton/dedupe_zero
[civicrm-core.git] / tests / phpunit / CRM / Core / I18n / LocaleTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27 /**
28 * Class CRM_Core_I18n_LocaleTest
29 * @group headless
30 */
31 class CRM_Core_I18n_LocaleTest extends CiviUnitTestCase {
32
33 public function setUp() {
34 parent::setUp();
35 }
36
37 public function tearDown() {
38 parent::tearDown();
39 }
40
41 /**
42 *
43 */
44 public function testI18nLocaleChange() {
45 $this->enableMultilingual();
46 CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US');
47
48 CRM_Core_I18n::singleton()->setLocale('fr_CA');
49 $locale = CRM_Core_I18n::getLocale();
50
51 $this->assertEquals($locale, 'fr_CA');
52
53 CRM_Core_I18n::singleton()->setLocale('en_US');
54 CRM_Core_I18n_Schema::makeSinglelingual('en_US');
55 Civi::$statics['CRM_Core_I18n']['singleton'] = [];
56 }
57
58 public function testUiLanguages() {
59 $languages = [
60 'en_US' => 'English (United States)',
61 'fr_CA' => 'French (Canada)',
62 'de_DE' => 'German',
63 ];
64 $codes = array_keys($languages);
65 Civi::settings()->set('uiLanguages', $codes);
66
67 // Check we can retrieve the setting
68 $result = Civi::settings()->get('uiLanguages');
69 $this->assertEquals($codes, $result);
70
71 // Monolingual, codes
72 $result = CRM_Core_I18n::uiLanguages(TRUE);
73 $this->assertArrayValuesEqual($codes, $result);
74
75 // Monolingual, codes and language labels
76 $result = CRM_Core_I18n::uiLanguages();
77 $this->assertTreeEquals($languages, $result);
78
79 $this->enableMultilingual();
80 // Add fr_CA in db
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]);
84
85 // Multilingual, codes
86 $result = CRM_Core_I18n::uiLanguages(TRUE);
87 $this->assertArrayValuesEqual(['en_US', 'fr_CA'], $result);
88
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)',
94 ], $result);
95
96 CRM_Core_I18n::singleton()->setLocale('en_US');
97 CRM_Core_I18n_Schema::makeSinglelingual('en_US');
98 Civi::$statics['CRM_Core_I18n']['singleton'] = [];
99 }
100
101 }