xref: /webtrees/tests/app/I18NTest.php (revision b2ce94c6833c25934b40a7e6bc15985d50b5f42a)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees;
17
18use Fisharebest\Webtrees\I18N;
19
20/**
21 * Test harness for the class I18N
22 */
23class I18NTest extends \Fisharebest\Webtrees\TestCase
24{
25    /**
26     * Prepare the environment for these tests
27     */
28    public function setUp()
29    {
30        defined('WT_BASE_URL') || define('WT_BASE_URL', 'http://localhost/');
31        defined('WT_DATA_DIR') || define('WT_DATA_DIR', 'data/');
32        defined('WT_MODULES_DIR') || define('WT_MODULES_DIR', 'modules_v3/');
33        defined('WT_ROOT') || define('WT_ROOT', '');
34        I18N::init('en-US');
35    }
36
37    /**
38     * Test I18N::strtoupper()
39     *
40     * @todo test all locales
41     */
42    public function testStrtoupper()
43    {
44        $this->assertSame(I18N::strtoupper(''), '');
45        $this->assertSame(I18N::strtoupper('Abc'), 'ABC');
46    }
47
48    /**
49     * Test I18N::strtolower()
50     *
51     * @todo test all locales
52     */
53    public function testStrtolower()
54    {
55        $this->assertSame(I18N::strtolower(''), '');
56        $this->assertSame(I18N::strtolower('Abc'), 'abc');
57    }
58
59    /**
60     * Test I18N::strcasecmp()
61     *
62     * @todo test all locales
63     */
64    public function testStrcasecmp()
65    {
66        $this->assertSame(I18N::strcasecmp('', ''), 0);
67        $this->assertSame(I18N::strcasecmp('Abc', 'abc'), 0);
68        $this->assertTrue(I18N::strcasecmp('Abc', 'bcd') < 0);
69        $this->assertTrue(I18N::strcasecmp('bcd', 'ABC') > 0);
70        $this->assertTrue(I18N::strcasecmp('Abc', 'abcd') < 0);
71        $this->assertTrue(I18N::strcasecmp('Abcd', 'abc') > 0);
72    }
73
74    /**
75     * Test I18N::reverseText()
76     */
77    public function testReverseText()
78    {
79        // Create these strings carefully, as text editors can display them in confusing ways.
80        $rtl_abc = 'א' . 'ב' . 'ג';
81        $rtl_cba = 'ג' . 'ב' . 'א';
82        $rtl_123 = '١' . '٢' . '٣';
83
84        $this->assertSame(I18N::reverseText(''), '');
85        $this->assertSame(I18N::reverseText('abc123'), 'abc123');
86        $this->assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123');
87        $this->assertSame(I18N::reverseText('&lt;abc&gt;'), '<abc>');
88        $this->assertSame(I18N::reverseText('abc[123]'), 'abc[123]');
89        $this->assertSame(I18N::reverseText($rtl_123), $rtl_123);
90        $this->assertSame(I18N::reverseText($rtl_abc), $rtl_cba);
91        $this->assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba);
92        $this->assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba);
93        $this->assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123');
94        $this->assertSame(I18N::reverseText($rtl_abc . '&lt;'), '>' . $rtl_cba);
95    }
96
97    /**
98     * Test I18N::languageName()
99     */
100    public function testKnownLanguageName()
101    {
102        $this->assertSame('العربية', I18N::languageName('ar'));
103        $this->assertSame('Deutsch', I18N::languageName('de'));
104        $this->assertSame('Ελληνικά', I18N::languageName('el'));
105        $this->assertSame('British English', I18N::languageName('en-GB'));
106        $this->assertSame('français', I18N::languageName('fr'));
107    }
108
109    /**
110     * Test I18N::languageScript()
111     */
112    public function testLanguageScript()
113    {
114        $this->assertSame('Arab', I18N::languageScript('ar'));
115        $this->assertSame('Latn', I18N::languageScript('de'));
116        $this->assertSame('Grek', I18N::languageScript('el'));
117    }
118}
119