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
82
83
84
85
86
87
88
89
90
|
<?php
/**
* @file
* @author Santhosh Thottingal
* @copyright Copyright © 2012-2013, Santhosh Thottingal
* @license GPL-2.0-or-later
*/
/**
* Unit tests for blacklisting/whitelisting languages for a message group
*/
class BlackListTest extends MediaWikiTestCase {
/**
* @var MessageGroup
*/
protected $group;
protected $codes;
protected $groupConfiguration = [
'BASIC' => [
'class' => FileBasedMessageGroup::class,
'id' => 'test-id',
'label' => 'Test Label',
'namespace' => 'NS_MEDIAWIKI',
'description' => 'Test description',
],
'FILES' => [
'class' => TestFFS::class,
],
];
protected function setUp() : void {
parent::setUp();
$this->group = MessageGroupBase::factory( $this->groupConfiguration );
$this->codes = array_flip( array_keys( TranslateUtils::getLanguageNames( 'en' ) ) );
}
protected function tearDown() : void {
unset( $this->group );
parent::tearDown();
}
public function testNoLanguageConf() {
$translatableLanguages = $this->group->getTranslatableLanguages();
$this->assertNull( $translatableLanguages );
}
public function testAllBlackList() {
$conf = $this->groupConfiguration;
$conf['LANGUAGES'] = [
'blacklist' => '*',
];
$group = MessageGroupBase::factory( $conf );
$translatableLanguages = $group->getTranslatableLanguages();
$this->assertEquals( count( $translatableLanguages ), 0 );
}
public function testAllWhiteList() {
$conf = $this->groupConfiguration;
$conf['LANGUAGES'] = [
'whitelist' => '*',
];
$group = MessageGroupBase::factory( $conf );
$translatableLanguages = $group->getTranslatableLanguages();
$this->assertNull( $translatableLanguages );
}
public function testWhiteListOverrideBlackList() {
$conf = $this->groupConfiguration;
$conf['LANGUAGES'] = [
'whitelist' => [ 'en', 'hi', 'ta' ],
'blacklist' => [ 'ta' ],
];
$group = MessageGroupBase::factory( $conf );
$translatableLanguages = $group->getTranslatableLanguages();
$this->assertTrue( isset( $translatableLanguages['ta'] ) );
$this->assertTrue( isset( $translatableLanguages['hi'] ) );
}
public function testSomeBlackList() {
$conf = $this->groupConfiguration;
$conf['LANGUAGES'] = [
'blacklist' => [ 'or', 'hi' ],
];
$group = MessageGroupBase::factory( $conf );
$translatableLanguages = $group->getTranslatableLanguages();
$this->assertTrue( !isset( $translatableLanguages['hi'] ) );
$this->assertTrue( isset( $translatableLanguages['he'] ) );
}
}
|