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