xref: /webtrees/tests/app/I18NTest.php (revision ad7270802ba57a28d195fc58fcc55f26458a779a)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 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 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees;
19
20/**
21 * Test harness for the class I18N
22 */
23class I18NTest extends TestCase
24{
25    /**
26     * @covers \Fisharebest\Webtrees\I18N::strtoupper
27     *
28     * @return void
29     */
30    public function testStrtoupper(): void
31    {
32        $this->assertSame(I18N::strtoupper(''), '');
33        $this->assertSame(I18N::strtoupper('Abc'), 'ABC');
34    }
35
36    /**
37     * @covers \Fisharebest\Webtrees\I18N::strtolower
38     *
39     * @return void
40     */
41    public function testStrtolower(): void
42    {
43        $this->assertSame(I18N::strtolower(''), '');
44        $this->assertSame(I18N::strtolower('Abc'), 'abc');
45    }
46
47    /**
48     * @covers \Fisharebest\Webtrees\I18N::strcasecmp()
49     *
50     * @return void
51     */
52    public function testStrcasecmp(): void
53    {
54        $this->assertSame(I18N::strcasecmp('', ''), 0);
55        $this->assertSame(I18N::strcasecmp('Abc', 'abc'), 0);
56        $this->assertTrue(I18N::strcasecmp('Abc', 'bcd') < 0);
57        $this->assertTrue(I18N::strcasecmp('bcd', 'ABC') > 0);
58        $this->assertTrue(I18N::strcasecmp('Abc', 'abcd') < 0);
59        $this->assertTrue(I18N::strcasecmp('Abcd', 'abc') > 0);
60    }
61
62    /**
63     * @covers \Fisharebest\Webtrees\I18N::reverseText
64     *
65     * @return void
66     */
67    public function testReverseText(): void
68    {
69        // Create these strings carefully, as text editors can display them in confusing ways.
70        $rtl_abc = 'א' . 'ב' . 'ג';
71        $rtl_cba = 'ג' . 'ב' . 'א';
72        $rtl_123 = '١' . '٢' . '٣';
73
74        $this->assertSame(I18N::reverseText(''), '');
75        $this->assertSame(I18N::reverseText('abc123'), 'abc123');
76        $this->assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123');
77        $this->assertSame(I18N::reverseText('&lt;abc&gt;'), '<abc>');
78        $this->assertSame(I18N::reverseText('abc[123]'), 'abc[123]');
79        $this->assertSame(I18N::reverseText($rtl_123), $rtl_123);
80        $this->assertSame(I18N::reverseText($rtl_abc), $rtl_cba);
81        $this->assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba);
82        $this->assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba);
83        $this->assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123');
84        $this->assertSame(I18N::reverseText($rtl_abc . '&lt;'), '>' . $rtl_cba);
85    }
86
87    /**
88     * @covers \Fisharebest\Webtrees\I18N::languageName
89     *
90     * @return void
91     */
92    public function testKnownLanguageName(): void
93    {
94        $this->assertSame('العربية', I18N::languageName('ar'));
95        $this->assertSame('Deutsch', I18N::languageName('de'));
96        $this->assertSame('Ελληνικά', I18N::languageName('el'));
97        $this->assertSame('British English', I18N::languageName('en-GB'));
98        $this->assertSame('français', I18N::languageName('fr'));
99    }
100
101    /**
102     * @covers \Fisharebest\Webtrees\I18N::languageScript
103     *
104     * @return void
105     */
106    public function testLanguageScript(): void
107    {
108        $this->assertSame('Arab', I18N::languageScript('ar'));
109        $this->assertSame('Latn', I18N::languageScript('de'));
110        $this->assertSame('Grek', I18N::languageScript('el'));
111    }
112}
113