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