3 use MediaWiki\Message\Message
;
4 use MediaWiki\Permissions\PermissionStatus
;
5 use Wikimedia\TestingAccessWrapper
;
8 * @covers \PermissionsError
10 class PermissionsErrorTest
extends MediaWikiIntegrationTestCase
{
12 protected function setUp(): void
{
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 ) ];
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() {
54 yield
[ null, new PermissionStatus() ];
58 * @dataProvider provideInvalidConstruction
60 public function testInvalidConstruction( $permission, $errors ) {
61 $this->expectException( InvalidArgumentException
::class );
62 $e = new PermissionsError( $permission, $errors );