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