xref: /webtrees/tests/app/I18NTest.php (revision 24931b29a0237a5f5f1b8620af661ea530451af0)
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    public function testStrtoupper(): void
31    {
32        self::assertSame(I18N::strtoupper(''), '');
33        self::assertSame(I18N::strtoupper('Abc'), 'ABC');
34    }
35
36    /**
37     * @covers \Fisharebest\Webtrees\I18N::strtolower
38     */
39    public function testStrtolower(): void
40    {
41        self::assertSame(I18N::strtolower(''), '');
42        self::assertSame(I18N::strtolower('Abc'), 'abc');
43    }
44
45    /**
46     * @covers \Fisharebest\Webtrees\I18N::comparator()
47     */
48    public function testComparator(): void
49    {
50        $comparator = I18N::comparator();
51
52        self::assertSame($comparator('', ''), 0);
53        self::assertSame($comparator('Abc', 'abc'), 0);
54        self::assertTrue($comparator('Abc', 'bcd') < 0);
55        self::assertTrue($comparator('bcd', 'ABC') > 0);
56        self::assertTrue($comparator('Abc', 'abcd') < 0);
57        self::assertTrue($comparator('Abcd', 'abc') > 0);
58    }
59
60    /**
61     * @covers \Fisharebest\Webtrees\I18N::reverseText
62     */
63    public function testReverseText(): void
64    {
65        // Create these strings carefully, as text editors can display them in confusing ways.
66        $rtl_abc = 'א' . 'ב' . 'ג';
67        $rtl_cba = 'ג' . 'ב' . 'א';
68        $rtl_123 = '١' . '٢' . '٣';
69
70        self::assertSame(I18N::reverseText(''), '');
71        self::assertSame(I18N::reverseText('abc123'), 'abc123');
72        self::assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123');
73        self::assertSame(I18N::reverseText('&lt;abc&gt;'), '<abc>');
74        self::assertSame(I18N::reverseText('abc[123]'), 'abc[123]');
75        self::assertSame(I18N::reverseText($rtl_123), $rtl_123);
76        self::assertSame(I18N::reverseText($rtl_abc), $rtl_cba);
77        self::assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba);
78        self::assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba);
79        self::assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123');
80        self::assertSame(I18N::reverseText($rtl_abc . '&lt;'), '>' . $rtl_cba);
81    }
82}
83