summaryrefslogtreecommitdiff
blob: 1789e2926c3008ce80f19c8a212891d75f0468f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php

namespace Babel\Tests;

use BabelLanguageCodes;
use LanguageCode;

/**
 * @covers BabelLanguageCodes
 *
 * @group Babel
 *
 * @license GPL-2.0-or-later
 * @author Thiemo Kreuz
 */
class BabelLanguageCodesTest extends \PHPUnit\Framework\TestCase {

	/**
	 * @dataProvider getCodeProvider
	 */
	public function testGetCode( $code, $expected ) {
		$this->assertSame( $expected, BabelLanguageCodes::getCode( $code ) );
	}

	public function getCodeProvider() {
		$testData = [
			[ 'invalidLanguageCode', false ],
			[ 'en', 'en' ],
			[ 'eng', 'en' ],
			[ 'en-gb', 'en-gb' ],
			[ 'de', 'de' ],
			[ 'be-x-old', 'be-tarask' ],
		];
		// True BCP 47 normalization was added in MW 1.32
		if ( LanguageCode::bcp47( 'simple' ) === 'en-simple' ) {
			// ensure BCP 47-compliant codes are mapped to MediaWiki's
			// nonstandard internal codes
			$testData = array_merge( $testData, [
				[ 'en-simple', 'simple' ],
				[ 'cbk', 'cbk-zam' ],
			] );
		}
		return $testData;
	}

	/**
	 * @dataProvider getNameProvider
	 */
	public function testGetName( $code, $language, $expected ) {
		$this->assertSame( $expected, BabelLanguageCodes::getName( $code, $language ) );
	}

	public function getNameProvider() {
		return [
			[ 'invalidLanguageCode', null, false ],
			[ 'en', null, 'English' ],
			[ 'en', 'en', 'English' ],
			[ 'eng', null, 'English' ],
			[ 'en-gb', null, 'British English' ],
			[ 'de', null, 'Deutsch' ],
			[ 'aaq', null, 'Eastern Abnaki' ],
		];
	}

	/**
	 * @dataProvider getCategoryCodeProvider
	 */
	public function testGetCategoryCode( $code, $expected ) {
		$this->assertSame( $expected, BabelLanguageCodes::getCategoryCode( $code ) );
	}

	public function getCategoryCodeProvider() {
		return [
			[ 'en', 'en' ],
			[ 'de', 'de' ],
			[ 'simple', 'simple' ],
			[ 'zh-hant', 'zh-Hant' ],
		];
	}

}