File: LanguageFactoryIntegrationTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (76 lines) | stat: -rw-r--r-- 2,176 bytes parent folder | download
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
<?php
namespace MediaWiki\Tests\Languages;

use MediaWikiIntegrationTestCase;
use Wikimedia\Bcp47Code\Bcp47CodeValue;

/**
 * @group Language
 * @covers \MediaWiki\Languages\LanguageFactory
 */
class LanguageFactoryIntegrationTest extends MediaWikiIntegrationTestCase {
	private function createFactory() {
		return $this->getServiceContainer()->getLanguageFactory();
	}

	/**
	 * @dataProvider provideCodes
	 */
	public function testGetParentLanguage( $code, $ignore, $parent = null ) {
		$factory = $this->createFactory();
		$lang = $factory->getParentLanguage( $code );
		$this->assertSame( $parent, $lang ? $lang->getCode() : null );
	}

	/**
	 * @dataProvider provideCodes
	 */
	public function testGetParentLanguageBcp47Code( $ignore, $bcp47code, $parent = null ) {
		$factory = $this->createFactory();
		$bcp47obj = new Bcp47CodeValue( $bcp47code );
		$lang = $factory->getParentLanguage( $bcp47obj );
		$this->assertSame( $parent, $lang ? $lang->getCode() : null );
	}

	public static function provideCodes() {
		return [
			# Basic codes
			[ 'de', 'de' ],
			[ 'fr', 'fr' ],
			[ 'ja', 'ja' ],
			# Base languages with variants are their own parents
			[ 'en', 'en', 'en' ],
			[ 'sr', 'sr', 'sr' ],
			[ 'crh', 'crh', 'crh' ],
			[ 'zh', 'zh', 'zh' ],
			# Variant codes
			[ 'zh-hans', 'zh-Hans', 'zh' ],
			# Non standard codes
			# Unlike deprecated codes, this *are* valid internal codes and
			# will be returned from Language::getCode()
			[ 'cbk-zam', 'cbk' ],
			[ 'de-formal', 'de-x-formal' ],
			[ 'eml', 'egl' ],
			[ 'en-rtl', 'en-x-rtl' ],
			[ 'es-formal', 'es-x-formal' ],
			[ 'hu-formal', 'hu-x-formal' ],
			[ 'map-bms', 'jv-x-bms' ],
			[ 'mo', 'ro-Cyrl-MD' ],
			[ 'nrm', 'nrf' ],
			[ 'nl-informal', 'nl-x-informal' ],
			[ 'roa-tara', 'nap-x-tara' ],
			[ 'simple', 'en-simple' ],
			[ 'sr-ec', 'sr-Cyrl', 'sr' ],
			[ 'sr-el', 'sr-Latn', 'sr' ],
			[ 'zh-cn', 'zh-Hans-CN', 'zh' ],
			[ 'zh-sg', 'zh-Hans-SG', 'zh' ],
			[ 'zh-my', 'zh-Hans-MY', 'zh' ],
			[ 'zh-tw', 'zh-Hant-TW', 'zh' ],
			[ 'zh-hk', 'zh-Hant-HK', 'zh' ],
			[ 'zh-mo', 'zh-Hant-MO', 'zh' ],
			[ 'zh-hans', 'zh-Hans', 'zh' ],
			[ 'zh-hant', 'zh-Hant', 'zh' ],
		];
	}

}