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