Merge pull request #15326 from totten/master-headfoot-2
[civicrm-core.git] / tests / phpunit / CRM / Core / I18n / LocaleTest.php
CommitLineData
65b98aa2
ML
1<?php
2/*
3 +--------------------------------------------------------------------+
7d61e75f 4 | Copyright CiviCRM LLC. All rights reserved. |
65b98aa2 5 | |
7d61e75f
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
65b98aa2
ML
9 +--------------------------------------------------------------------+
10 */
11/**
12 * Class CRM_Core_I18n_LocaleTest
13 * @group headless
14 */
15class CRM_Core_I18n_LocaleTest extends CiviUnitTestCase {
16
17 public function setUp() {
18 parent::setUp();
19 }
20
21 public function tearDown() {
65b98aa2
ML
22 parent::tearDown();
23 }
24
25 /**
26 *
27 */
28 public function testI18nLocaleChange() {
29 $this->enableMultilingual();
30 CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US');
31
32 CRM_Core_I18n::singleton()->setLocale('fr_CA');
33 $locale = CRM_Core_I18n::getLocale();
34
35 $this->assertEquals($locale, 'fr_CA');
47c1c8a1 36
9d65201d 37 CRM_Core_I18n::singleton()->setLocale('en_US');
47c1c8a1
AS
38 CRM_Core_I18n_Schema::makeSinglelingual('en_US');
39 Civi::$statics['CRM_Core_I18n']['singleton'] = [];
40 }
41
42 public function testUiLanguages() {
43 $languages = [
44 'en_US' => 'English (United States)',
45 'fr_CA' => 'French (Canada)',
46 'de_DE' => 'German',
47 ];
48 $codes = array_keys($languages);
49 Civi::settings()->set('uiLanguages', $codes);
50
51 // Check we can retrieve the setting
52 $result = Civi::settings()->get('uiLanguages');
53 $this->assertEquals($codes, $result);
54
55 // Monolingual, codes
56 $result = CRM_Core_I18n::uiLanguages(TRUE);
57 $this->assertArrayValuesEqual($codes, $result);
58
59 // Monolingual, codes and language labels
60 $result = CRM_Core_I18n::uiLanguages();
61 $this->assertTreeEquals($languages, $result);
62
63 $this->enableMultilingual();
64 // Add fr_CA in db
65 CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US');
66 // Make fr_CA 'available'
67 Civi::settings()->set('languageLimit', ['en_US' => 1, 'fr_CA' => 1]);
68
69 // Multilingual, codes
70 $result = CRM_Core_I18n::uiLanguages(TRUE);
71 $this->assertArrayValuesEqual(['en_US', 'fr_CA'], $result);
72
73 // Multilingual, codes and language labels
74 $result = CRM_Core_I18n::uiLanguages();
75 $this->assertTreeEquals([
76 'en_US' => 'English (United States)',
77 'fr_CA' => 'French (Canada)',
39b959db 78 ], $result);
47c1c8a1
AS
79
80 CRM_Core_I18n::singleton()->setLocale('en_US');
81 CRM_Core_I18n_Schema::makeSinglelingual('en_US');
9d65201d 82 Civi::$statics['CRM_Core_I18n']['singleton'] = [];
65b98aa2
ML
83 }
84
85}