xref: /webtrees/tests/app/I18NTest.php (revision 81b514b4672980e5db010e9d89b55eaf131e798f)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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 <https://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        self::assertSame(I18N::strtoupper(''), '');
35        self::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        self::assertSame(I18N::strtolower(''), '');
46        self::assertSame(I18N::strtolower('Abc'), 'abc');
47    }
48
49    /**
50     * @covers \Fisharebest\Webtrees\I18N::comparator()
51     *
52     * @return void
53     */
54    public function testComparator(): void
55    {
56        $comparator = I18N::comparator();
57
58        self::assertSame($comparator('', ''), 0);
59        self::assertSame($comparator('Abc', 'abc'), 0);
60        self::assertTrue($comparator('Abc', 'bcd') < 0);
61        self::assertTrue($comparator('bcd', 'ABC') > 0);
62        self::assertTrue($comparator('Abc', 'abcd') < 0);
63        self::assertTrue($comparator('Abcd', 'abc') > 0);
64    }
65
66    /**
67     * @covers \Fisharebest\Webtrees\I18N::reverseText
68     *
69     * @return void
70     */
71    public function testReverseText(): void
72    {
73        // Create these strings carefully, as text editors can display them in confusing ways.
74        $rtl_abc = 'א' . 'ב' . 'ג';
75        $rtl_cba = 'ג' . 'ב' . 'א';
76        $rtl_123 = '١' . '٢' . '٣';
77
78        self::assertSame(I18N::reverseText(''), '');
79        self::assertSame(I18N::reverseText('abc123'), 'abc123');
80        self::assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123');
81        self::assertSame(I18N::reverseText('&lt;abc&gt;'), '<abc>');
82        self::assertSame(I18N::reverseText('abc[123]'), 'abc[123]');
83        self::assertSame(I18N::reverseText($rtl_123), $rtl_123);
84        self::assertSame(I18N::reverseText($rtl_abc), $rtl_cba);
85        self::assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba);
86        self::assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba);
87        self::assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123');
88        self::assertSame(I18N::reverseText($rtl_abc . '&lt;'), '>' . $rtl_cba);
89    }
90}
91