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
91
92
93
94
95
|
<?php
namespace MediaWiki\Tests\Integration\Permissions;
use HtmlArmor;
use MediaWiki\Html\Html;
use MediaWiki\Message\Message;
use MediaWiki\Permissions\GrantsLocalization;
use MediaWiki\SpecialPage\SpecialPage;
use MediaWikiIntegrationTestCase;
/**
* @author Zabe
*
* @covers \MediaWiki\Permissions\GrantsLocalization
*/
class GrantsLocalizationTest extends MediaWikiIntegrationTestCase {
private GrantsLocalization $grantsLocalization;
protected function setUp(): void {
parent::setUp();
$this->grantsLocalization = $this->getServiceContainer()->getGrantsLocalization();
}
/**
* @dataProvider grantDescriptions
*/
public function testGetGrantDescription( string $grant ) {
$message = new Message( 'grant-' . $grant );
$this->assertSame(
$message->text(),
$this->grantsLocalization->getGrantDescription( $grant )
);
$this->assertSame(
$message->inLanguage( 'de' )->text(),
$this->grantsLocalization->getGrantDescription( $grant, 'de' )
);
}
public function grantDescriptions() {
yield [ 'blockusers' ];
yield [ 'createeditmovepage' ];
yield [ 'delete' ];
}
public function testGetNonExistingGrantDescription() {
$message = ( new Message( 'grant-generic' ) )->params( 'foo' );
$this->assertSame(
$message->text(),
$this->grantsLocalization->getGrantDescription( 'foo' )
);
$this->assertSame(
$message->inLanguage( 'zh' )->text(),
$this->grantsLocalization->getGrantDescription( 'foo', 'zh' )
);
}
public function testGetGrantDescriptions() {
$this->assertSame(
[
'blockusers' => ( new Message( 'grant-blockusers' ) )->inLanguage( 'de' )->text(),
'delete' => ( new Message( 'grant-delete' ) )->inLanguage( 'de' )->text(),
],
$this->grantsLocalization->getGrantDescriptions(
[
'blockusers',
'delete',
],
'de'
)
);
}
public function testGetGrantsLink() {
$this->assertSame(
$this->getServiceContainer()->getLinkRenderer()->makeKnownLink(
SpecialPage::getTitleFor( 'Listgrants', false, 'delete' ),
new HtmlArmor(
( new Message( 'grant-delete' ) )->escaped() . ' ' .
Html::element( 'span', [ 'class' => 'mw-grant mw-grantriskgroup-vandalism' ],
( new Message( 'grantriskgroup-vandalism' ) )->text() )
)
),
$this->grantsLocalization->getGrantsLink( 'delete' )
);
}
public function testGetGrantsWikiText() {
$this->assertSame(
"*<span class=\"mw-grantgroup\">Perform high volume activity</span>\n:High-volume (bot) access <span class=\"mw-grant mw-grantriskgroup-low\"></span>\n\n",
$this->grantsLocalization->getGrantsWikiText( [ 'highvolume' ] )
);
}
}
|