1<?php 2namespace Fisharebest\Webtrees; 3 4/** 5 * webtrees: online genealogy 6 * Copyright (C) 2015 webtrees development team 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19use PHPUnit_Framework_TestCase; 20 21/** 22 * Test harness for the class I18N 23 */ 24class I18NTest extends PHPUnit_Framework_TestCase { 25 /** 26 * Prepare the environment for these tests 27 * 28 * @return void 29 */ 30 public function setUp() { 31 \Patchwork\Utf8\Bootup::initAll(); 32 \Patchwork\Utf8\Bootup::filterRequestUri(); 33 \Patchwork\Utf8\Bootup::filterRequestInputs(); 34 defined('WT_BASE_URL') || define('WT_BASE_URL', 'http://localhost/'); 35 defined('WT_DATA_DIR') || define('WT_DATA_DIR', 'data/'); 36 I18N::init('en-US'); 37 } 38 39 /** 40 * Test I18N::strtoupper() 41 * 42 * @todo test all locales 43 * 44 * @return void 45 */ 46 public function testStrtoupper() { 47 $this->assertSame(I18N::strtoupper(''), ''); 48 $this->assertSame(I18N::strtoupper('Abc'), 'ABC'); 49 } 50 51 /** 52 * Test I18N::strtolower() 53 * 54 * @todo test all locales 55 * 56 * @return void 57 */ 58 public function testStrtolower() { 59 $this->assertSame(I18N::strtolower(''), ''); 60 $this->assertSame(I18N::strtolower('Abc'), 'abc'); 61 } 62 63 /** 64 * Test I18N::strcasecmp() 65 * 66 * @todo test all locales 67 * 68 * @return void 69 */ 70 public function testStrcasecmp() { 71 $this->assertSame(I18N::strcasecmp('', ''), 0); 72 $this->assertSame(I18N::strcasecmp('Abc', 'abc'), 0); 73 $this->assertTrue(I18N::strcasecmp('Abc', 'bcd') < 0); 74 $this->assertTrue(I18N::strcasecmp('bcd', 'ABC') > 0); 75 $this->assertTrue(I18N::strcasecmp('Abc', 'abcd') < 0); 76 $this->assertTrue(I18N::strcasecmp('Abcd', 'abc') > 0); 77 } 78 79 /** 80 * Test I18N::reverseText() 81 * 82 * @return void 83 */ 84 public function testReverseText() { 85 // Create these strings carefully, as text editors can display them in confusing ways. 86 $rtl_abc = 'א' . 'ב' . 'ג'; 87 $rtl_cba = 'ג' . 'ב' . 'א'; 88 $rtl_123 = '١' . '٢' . '٣'; 89 90 $this->assertSame(I18N::reverseText(''), ''); 91 $this->assertSame(I18N::reverseText('abc123'), 'abc123'); 92 $this->assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123'); 93 $this->assertSame(I18N::reverseText('<abc>'), '<abc>'); 94 $this->assertSame(I18N::reverseText('abc[123]'), 'abc[123]'); 95 $this->assertSame(I18N::reverseText($rtl_123), $rtl_123); 96 $this->assertSame(I18N::reverseText($rtl_abc), $rtl_cba); 97 $this->assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba); 98 $this->assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba); 99 $this->assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123'); 100 $this->assertSame(I18N::reverseText($rtl_abc . '<'), '>' . $rtl_cba); 101 } 102 103 /** 104 * Test I18N::languageName() 105 * 106 * @return void 107 */ 108 public function testKnownLanguageName() { 109 $this->assertSame('العربية', I18N::languageName('ar')); 110 $this->assertSame('Deutsch', I18N::languageName('de')); 111 $this->assertSame('Ελληνικά', I18N::languageName('el')); 112 $this->assertSame('British English', I18N::languageName('en-GB')); 113 $this->assertSame('français', I18N::languageName('fr')); 114 } 115 116 /** 117 * Test I18N::languageScript() 118 * 119 * @return void 120 */ 121 public function testLanguageScript() { 122 $this->assertSame('Arab', I18N::languageScript('ar')); 123 $this->assertSame('Latn', I18N::languageScript('de')); 124 $this->assertSame('Grek', I18N::languageScript('el')); 125 } 126} 127