Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / exception / PermissionsErrorTest.php
blobe94fe45e139dda14f1210cec7b54dcb9a09c2782
1 <?php
3 use MediaWiki\Message\Message;
4 use MediaWiki\Permissions\PermissionStatus;
5 use Wikimedia\TestingAccessWrapper;
7 /**
8 * @covers \PermissionsError
9 */
10 class PermissionsErrorTest extends MediaWikiIntegrationTestCase {
12 protected function setUp(): void {
13 parent::setUp();
14 $this->setGroupPermissions( '*', 'testpermission', true );
17 public static function provideConstruction() {
18 $status = new PermissionStatus();
19 $status->error( 'cat', 1, 2 );
20 $status->error( 'dog', 3, 4 );
21 $array = [ [ 'cat', 1, 2 ], [ 'dog', 3, 4 ] ];
22 yield [ null, $status, $status ];
23 yield [ null, $array, $status ];
24 yield [ 'testpermission', $status, $status ];
25 yield [ 'testpermission', $array, $status ];
27 yield [ 'testpermission', [],
28 PermissionStatus::newEmpty()->fatal( 'badaccess-groups', Message::listParam( [ '*' ], 'comma' ), 1 ) ];
31 /**
32 * @dataProvider provideConstruction
34 public function testConstruction( $permission, $errors, $expected ) {
35 $e = new PermissionsError( $permission, $errors );
36 $et = TestingAccessWrapper::newFromObject( $e );
38 $this->expectDeprecationAndContinue( '/Use of PermissionsError::\\$permission/' );
39 $this->assertEquals( $permission, $e->permission );
41 $this->assertStatusMessagesExactly( $expected, $et->status );
43 $this->expectDeprecationAndContinue( '/Use of PermissionsError::\\$errors/' );
44 $this->assertArrayEquals( $expected->toLegacyErrorArray(), $e->errors );
46 // Test the deprecated public property setter
47 $e->errors = $e->errors;
48 $this->assertStatusMessagesExactly( $expected, $et->status );
51 public static function provideInvalidConstruction() {
52 yield [ null, null ];
53 yield [ null, [] ];
54 yield [ null, new PermissionStatus() ];
57 /**
58 * @dataProvider provideInvalidConstruction
60 public function testInvalidConstruction( $permission, $errors ) {
61 $this->expectException( InvalidArgumentException::class );
62 $e = new PermissionsError( $permission, $errors );