| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Integration\Permissions; |
| 4 |
|
| 5 |
use HtmlArmor; |
| 6 |
use MediaWiki\Html\Html; |
| 7 |
use MediaWiki\Message\Message; |
| 8 |
use MediaWiki\Permissions\GrantsLocalization; |
| 9 |
use MediaWiki\SpecialPage\SpecialPage; |
| 10 |
use MediaWikiIntegrationTestCase; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class GrantsLocalizationTest extends MediaWikiIntegrationTestCase { |
| 18 |
private GrantsLocalization $grantsLocalization; |
| 19 |
|
| 20 |
protected function setUp(): void { |
| 21 |
parent::setUp(); |
| 22 |
|
| 23 |
$this->grantsLocalization = $this->getServiceContainer()->getGrantsLocalization(); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public function testGetGrantDescription( string $grant ) { |
| 30 |
$message = new Message( 'grant-' . $grant ); |
| 31 |
$this->assertSame( |
| 32 |
$message->text(), |
| 33 |
$this->grantsLocalization->getGrantDescription( $grant ) |
| 34 |
); |
| 35 |
$this->assertSame( |
| 36 |
$message->inLanguage( 'de' )->text(), |
| 37 |
$this->grantsLocalization->getGrantDescription( $grant, 'de' ) |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
public function grantDescriptions() { |
| 42 |
yield [ 'blockusers' ]; |
| 43 |
yield [ 'createeditmovepage' ]; |
| 44 |
yield [ 'delete' ]; |
| 45 |
} |
| 46 |
|
| 47 |
public function testGetNonExistingGrantDescription() { |
| 48 |
$message = ( new Message( 'grant-generic' ) )->params( 'foo' ); |
| 49 |
$this->assertSame( |
| 50 |
$message->text(), |
| 51 |
$this->grantsLocalization->getGrantDescription( 'foo' ) |
| 52 |
); |
| 53 |
$this->assertSame( |
| 54 |
$message->inLanguage( 'zh' )->text(), |
| 55 |
$this->grantsLocalization->getGrantDescription( 'foo', 'zh' ) |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
public function testGetGrantDescriptions() { |
| 60 |
$this->assertSame( |
| 61 |
[ |
| 62 |
'blockusers' => ( new Message( 'grant-blockusers' ) )->inLanguage( 'de' )->text(), |
| 63 |
'delete' => ( new Message( 'grant-delete' ) )->inLanguage( 'de' )->text(), |
| 64 |
], |
| 65 |
$this->grantsLocalization->getGrantDescriptions( |
| 66 |
[ |
| 67 |
'blockusers', |
| 68 |
'delete', |
| 69 |
], |
| 70 |
'de' |
| 71 |
) |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
public function testGetGrantsLink() { |
| 76 |
$this->assertSame( |
| 77 |
$this->getServiceContainer()->getLinkRenderer()->makeKnownLink( |
| 78 |
SpecialPage::getTitleFor( 'Listgrants', false, 'delete' ), |
| 79 |
new HtmlArmor( |
| 80 |
( new Message( 'grant-delete' ) )->escaped() . ' ' . |
| 81 |
Html::element( 'span', [ 'class' => 'mw-grant mw-grantriskgroup-vandalism' ], |
| 82 |
( new Message( 'grantriskgroup-vandalism' ) )->text() ) |
| 83 |
) |
| 84 |
), |
| 85 |
$this->grantsLocalization->getGrantsLink( 'delete' ) |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
public function testGetGrantsWikiText() { |
| 90 |
$this->assertSame( |
| 91 |
"*<span class=\"mw-grantgroup\">Perform high volume activity</span>\n:High-volume (bot) access <span class=\"mw-grant mw-grantriskgroup-low\"></span>\n\n", |
| 92 |
$this->grantsLocalization->getGrantsWikiText( [ 'highvolume' ] ) |
| 93 |
); |
| 94 |
} |
| 95 |
} |