1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2018 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 18use Fisharebest\Webtrees\I18N; 19 20/** 21 * Test harness for the class I18N 22 */ 23class I18NTest extends \PHPUnit\Framework\TestCase { 24 /** 25 * Prepare the environment for these tests 26 */ 27 public function setUp() { 28 defined('WT_BASE_URL') || define('WT_BASE_URL', 'http://localhost/'); 29 defined('WT_DATA_DIR') || define('WT_DATA_DIR', 'data/'); 30 defined('WT_MODULES_DIR') || define('WT_MODULES_DIR', 'modules_v3/'); 31 defined('WT_ROOT') || define('WT_ROOT', ''); 32 I18N::init('en-US'); 33 } 34 35 /** 36 * Test I18N::strtoupper() 37 * 38 * @todo test all locales 39 */ 40 public function testStrtoupper() { 41 $this->assertSame(I18N::strtoupper(''), ''); 42 $this->assertSame(I18N::strtoupper('Abc'), 'ABC'); 43 } 44 45 /** 46 * Test I18N::strtolower() 47 * 48 * @todo test all locales 49 */ 50 public function testStrtolower() { 51 $this->assertSame(I18N::strtolower(''), ''); 52 $this->assertSame(I18N::strtolower('Abc'), 'abc'); 53 } 54 55 /** 56 * Test I18N::strcasecmp() 57 * 58 * @todo test all locales 59 */ 60 public function testStrcasecmp() { 61 $this->assertSame(I18N::strcasecmp('', ''), 0); 62 $this->assertSame(I18N::strcasecmp('Abc', 'abc'), 0); 63 $this->assertTrue(I18N::strcasecmp('Abc', 'bcd') < 0); 64 $this->assertTrue(I18N::strcasecmp('bcd', 'ABC') > 0); 65 $this->assertTrue(I18N::strcasecmp('Abc', 'abcd') < 0); 66 $this->assertTrue(I18N::strcasecmp('Abcd', 'abc') > 0); 67 } 68 69 /** 70 * Test I18N::reverseText() 71 */ 72 public function testReverseText() { 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 $this->assertSame(I18N::reverseText(''), ''); 79 $this->assertSame(I18N::reverseText('abc123'), 'abc123'); 80 $this->assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123'); 81 $this->assertSame(I18N::reverseText('<abc>'), '<abc>'); 82 $this->assertSame(I18N::reverseText('abc[123]'), 'abc[123]'); 83 $this->assertSame(I18N::reverseText($rtl_123), $rtl_123); 84 $this->assertSame(I18N::reverseText($rtl_abc), $rtl_cba); 85 $this->assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba); 86 $this->assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba); 87 $this->assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123'); 88 $this->assertSame(I18N::reverseText($rtl_abc . '<'), '>' . $rtl_cba); 89 } 90 91 /** 92 * Test I18N::languageName() 93 */ 94 public function testKnownLanguageName() { 95 $this->assertSame('العربية', I18N::languageName('ar')); 96 $this->assertSame('Deutsch', I18N::languageName('de')); 97 $this->assertSame('Ελληνικά', I18N::languageName('el')); 98 $this->assertSame('British English', I18N::languageName('en-GB')); 99 $this->assertSame('français', I18N::languageName('fr')); 100 } 101 102 /** 103 * Test I18N::languageScript() 104 */ 105 public function testLanguageScript() { 106 $this->assertSame('Arab', I18N::languageScript('ar')); 107 $this->assertSame('Latn', I18N::languageScript('de')); 108 $this->assertSame('Grek', I18N::languageScript('el')); 109 } 110} 111