xref: /webtrees/tests/app/I18NTest.php (revision 18d7a90d8a3b33b218801c0b68eb1a5140d7b4e7)
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     * @return void
29     */
30    public function setUp()
31    {
32        defined('WT_BASE_URL') || define('WT_BASE_URL', 'http://localhost/');
33        defined('WT_DATA_DIR') || define('WT_DATA_DIR', 'data/');
34        defined('WT_MODULES_DIR') || define('WT_MODULES_DIR', 'modules_v3/');
35        defined('WT_ROOT') || define('WT_ROOT', '');
36        I18N::init('en-US');
37    }
38
39    /**
40     * Test I18N::strtoupper()
41     *
42     * @return void
43     */
44    public function testStrtoupper()
45    {
46        $this->assertSame(I18N::strtoupper(''), '');
47        $this->assertSame(I18N::strtoupper('Abc'), 'ABC');
48    }
49
50    /**
51     * Test I18N::strtolower()
52     *
53     * @return void
54     */
55    public function testStrtolower()
56    {
57        $this->assertSame(I18N::strtolower(''), '');
58        $this->assertSame(I18N::strtolower('Abc'), 'abc');
59    }
60
61    /**
62     * Test I18N::strcasecmp()
63     *
64     * @return void
65     */
66    public function testStrcasecmp()
67    {
68        $this->assertSame(I18N::strcasecmp('', ''), 0);
69        $this->assertSame(I18N::strcasecmp('Abc', 'abc'), 0);
70        $this->assertTrue(I18N::strcasecmp('Abc', 'bcd') < 0);
71        $this->assertTrue(I18N::strcasecmp('bcd', 'ABC') > 0);
72        $this->assertTrue(I18N::strcasecmp('Abc', 'abcd') < 0);
73        $this->assertTrue(I18N::strcasecmp('Abcd', 'abc') > 0);
74    }
75
76    /**
77     * Test I18N::reverseText()
78     *
79     * @return void
80     */
81    public function testReverseText()
82    {
83        // Create these strings carefully, as text editors can display them in confusing ways.
84        $rtl_abc = 'א' . 'ב' . 'ג';
85        $rtl_cba = 'ג' . 'ב' . 'א';
86        $rtl_123 = '١' . '٢' . '٣';
87
88        $this->assertSame(I18N::reverseText(''), '');
89        $this->assertSame(I18N::reverseText('abc123'), 'abc123');
90        $this->assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123');
91        $this->assertSame(I18N::reverseText('&lt;abc&gt;'), '<abc>');
92        $this->assertSame(I18N::reverseText('abc[123]'), 'abc[123]');
93        $this->assertSame(I18N::reverseText($rtl_123), $rtl_123);
94        $this->assertSame(I18N::reverseText($rtl_abc), $rtl_cba);
95        $this->assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba);
96        $this->assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba);
97        $this->assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123');
98        $this->assertSame(I18N::reverseText($rtl_abc . '&lt;'), '>' . $rtl_cba);
99    }
100
101    /**
102     * Test I18N::languageName()
103     *
104     * @return void
105     */
106    public function testKnownLanguageName()
107    {
108        $this->assertSame('العربية', I18N::languageName('ar'));
109        $this->assertSame('Deutsch', I18N::languageName('de'));
110        $this->assertSame('Ελληνικά', I18N::languageName('el'));
111        $this->assertSame('British English', I18N::languageName('en-GB'));
112        $this->assertSame('français', I18N::languageName('fr'));
113    }
114
115    /**
116     * Test I18N::languageScript()
117     *
118     * @return void
119     */
120    public function testLanguageScript()
121    {
122        $this->assertSame('Arab', I18N::languageScript('ar'));
123        $this->assertSame('Latn', I18N::languageScript('de'));
124        $this->assertSame('Grek', I18N::languageScript('el'));
125    }
126}
127