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