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