xref: /webtrees/tests/app/I18NTest.php (revision 0e62c4b8d0ec6901bfaffd1dc763db37489518a4)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2015 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		\Patchwork\Utf8\Bootup::initAll();
29		\Patchwork\Utf8\Bootup::filterRequestUri();
30		\Patchwork\Utf8\Bootup::filterRequestInputs();
31		defined('WT_BASE_URL') || define('WT_BASE_URL', 'http://localhost/');
32		defined('WT_DATA_DIR') || define('WT_DATA_DIR', 'data/');
33		defined('WT_MODULES_DIR') || define('WT_MODULES_DIR', 'modules_v3/');
34		I18N::init('en-US');
35	}
36
37	/**
38	 * Test I18N::strtoupper()
39	 *
40	 * @todo test all locales
41	 */
42	public function testStrtoupper() {
43		$this->assertSame(I18N::strtoupper(''), '');
44		$this->assertSame(I18N::strtoupper('Abc'), 'ABC');
45	}
46
47	/**
48	 * Test I18N::strtolower()
49	 *
50	 * @todo test all locales
51	 */
52	public function testStrtolower() {
53		$this->assertSame(I18N::strtolower(''), '');
54		$this->assertSame(I18N::strtolower('Abc'), 'abc');
55	}
56
57	/**
58	 * Test I18N::strcasecmp()
59	 *
60	 * @todo test all locales
61	 */
62	public function testStrcasecmp() {
63		$this->assertSame(I18N::strcasecmp('', ''), 0);
64		$this->assertSame(I18N::strcasecmp('Abc', 'abc'), 0);
65		$this->assertTrue(I18N::strcasecmp('Abc', 'bcd') < 0);
66		$this->assertTrue(I18N::strcasecmp('bcd', 'ABC') > 0);
67		$this->assertTrue(I18N::strcasecmp('Abc', 'abcd') < 0);
68		$this->assertTrue(I18N::strcasecmp('Abcd', 'abc') > 0);
69	}
70
71	/**
72	 * Test I18N::reverseText()
73	 */
74	public function testReverseText() {
75		// Create these strings carefully, as text editors can display them in confusing ways.
76		$rtl_abc = 'א' . 'ב' . 'ג';
77		$rtl_cba = 'ג' . 'ב' . 'א';
78		$rtl_123 = '١' . '٢' . '٣';
79
80		$this->assertSame(I18N::reverseText(''), '');
81		$this->assertSame(I18N::reverseText('abc123'), 'abc123');
82		$this->assertSame(I18N::reverseText('<b>abc</b>123'), 'abc123');
83		$this->assertSame(I18N::reverseText('&lt;abc&gt;'), '<abc>');
84		$this->assertSame(I18N::reverseText('abc[123]'), 'abc[123]');
85		$this->assertSame(I18N::reverseText($rtl_123), $rtl_123);
86		$this->assertSame(I18N::reverseText($rtl_abc), $rtl_cba);
87		$this->assertSame(I18N::reverseText($rtl_abc . '123'), '123' . $rtl_cba);
88		$this->assertSame(I18N::reverseText($rtl_abc . '[123]'), '[123]' . $rtl_cba);
89		$this->assertSame(I18N::reverseText('123' . $rtl_abc . '456'), '456' . $rtl_cba . '123');
90		$this->assertSame(I18N::reverseText($rtl_abc . '&lt;'), '>' . $rtl_cba);
91	}
92
93	/**
94	 * Test I18N::languageName()
95	 */
96	public function testKnownLanguageName() {
97		$this->assertSame('العربية', I18N::languageName('ar'));
98		$this->assertSame('Deutsch', I18N::languageName('de'));
99		$this->assertSame('Ελληνικά', I18N::languageName('el'));
100		$this->assertSame('British English', I18N::languageName('en-GB'));
101		$this->assertSame('français', I18N::languageName('fr'));
102	}
103
104	/**
105	 * Test I18N::languageScript()
106	 */
107	public function testLanguageScript() {
108		$this->assertSame('Arab', I18N::languageScript('ar'));
109		$this->assertSame('Latn', I18N::languageScript('de'));
110		$this->assertSame('Grek', I18N::languageScript('el'));
111	}
112}
113