xref: /webtrees/tests/app/I18NTest.php (revision 18fd0859d876caec952296f28638ed0844e10712)
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
22use PHPUnit\Framework\Attributes\CoversClass;
23
24#[CoversClass(I18N::class)]
25class I18NTest extends TestCase
26{
27    public function testStrtoupper(): void
28    {
29        self::assertSame(I18N::strtoupper(''), '');
30        self::assertSame(I18N::strtoupper('Abc'), 'ABC');
31    }
32
33    public function testStrtolower(): void
34    {
35        self::assertSame(I18N::strtolower(''), '');
36        self::assertSame(I18N::strtolower('Abc'), 'abc');
37    }
38
39    public function testComparator(): void
40    {
41        $comparator = I18N::comparator();
42
43        self::assertSame($comparator('', ''), 0);
44        self::assertSame($comparator('Abc', 'abc'), 0);
45        self::assertTrue($comparator('Abc', 'bcd') < 0);
46        self::assertTrue($comparator('bcd', 'ABC') > 0);
47        self::assertTrue($comparator('Abc', 'abcd') < 0);
48        self::assertTrue($comparator('Abcd', 'abc') > 0);
49    }
50
51    public function testReverseText(): void
52    {
53        // Create these strings carefully, as text editors can display them in confusing ways.
54        $rtl_abc = 'א' . 'ב' . 'ג';
55        $rtl_cba = 'ג' . 'ב' . 'א';
56        $rtl_123 = '١' . '٢' . '٣';
57
58        self::assertSame(I18N::reverseText(''), '');
59        self::assertSame(I18N::reverseText('abc123'), 'abc123');
60        self::assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123');
61        self::assertSame(I18N::reverseText('&lt;abc&gt;'), '<abc>');
62        self::assertSame(I18N::reverseText('abc[123]'), 'abc[123]');
63        self::assertSame(I18N::reverseText($rtl_123), $rtl_123);
64        self::assertSame(I18N::reverseText($rtl_abc), $rtl_cba);
65        self::assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba);
66        self::assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba);
67        self::assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123');
68        self::assertSame(I18N::reverseText($rtl_abc . '&lt;'), '>' . $rtl_cba);
69    }
70}
71