xref: /webtrees/tests/app/I18NTest.php (revision a0e7c4295c1f0b23b4dae10740838cc05665866f)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2020 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        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::strcasecmp()
51     *
52     * @return void
53     */
54    public function testStrcasecmp(): void
55    {
56        self::assertSame(I18N::strcasecmp('', ''), 0);
57        self::assertSame(I18N::strcasecmp('Abc', 'abc'), 0);
58        self::assertTrue(I18N::strcasecmp('Abc', 'bcd') < 0);
59        self::assertTrue(I18N::strcasecmp('bcd', 'ABC') > 0);
60        self::assertTrue(I18N::strcasecmp('Abc', 'abcd') < 0);
61        self::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        self::assertSame(I18N::reverseText(''), '');
77        self::assertSame(I18N::reverseText('abc123'), 'abc123');
78        self::assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123');
79        self::assertSame(I18N::reverseText('&lt;abc&gt;'), '<abc>');
80        self::assertSame(I18N::reverseText('abc[123]'), 'abc[123]');
81        self::assertSame(I18N::reverseText($rtl_123), $rtl_123);
82        self::assertSame(I18N::reverseText($rtl_abc), $rtl_cba);
83        self::assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba);
84        self::assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba);
85        self::assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123');
86        self::assertSame(I18N::reverseText($rtl_abc . '&lt;'), '>' . $rtl_cba);
87    }
88}
89