Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / utils / MWGrantsTest.php
blobeae9c15d824c181fef3808d7c92ae311ef975ce3
1 <?php
2 class MWGrantsTest extends MediaWikiTestCase {
4 protected function setUp() {
5 parent::setUp();
7 $this->setMwGlobals( [
8 'wgGrantPermissions' => [
9 'hidden1' => [ 'read' => true, 'autoconfirmed' => false ],
10 'hidden2' => [ 'autoconfirmed' => true ],
11 'normal' => [ 'edit' => true ],
12 'normal2' => [ 'edit' => true, 'create' => true ],
13 'admin' => [ 'protect' => true, 'delete' => true ],
15 'wgGrantPermissionGroups' => [
16 'hidden1' => 'hidden',
17 'hidden2' => 'hidden',
18 'normal' => 'normal-group',
19 'admin' => 'admin',
21 ] );
24 /**
25 * @covers MWGrants::getValidGrants
27 public function testGetValidGrants() {
28 $this->assertSame(
29 [ 'hidden1', 'hidden2', 'normal', 'normal2', 'admin' ],
30 MWGrants::getValidGrants()
34 /**
35 * @covers MWGrants::getRightsByGrant
37 public function testGetRightsByGrant() {
38 $this->assertSame(
40 'hidden1' => [ 'read' ],
41 'hidden2' => [ 'autoconfirmed' ],
42 'normal' => [ 'edit' ],
43 'normal2' => [ 'edit', 'create' ],
44 'admin' => [ 'protect', 'delete' ],
46 MWGrants::getRightsByGrant()
50 /**
51 * @dataProvider provideGetGrantRights
52 * @covers MWGrants::getGrantRights
53 * @param array|string $grants
54 * @param array $rights
56 public function testGetGrantRights( $grants, $rights ) {
57 $this->assertSame( $rights, MWGrants::getGrantRights( $grants ) );
60 public static function provideGetGrantRights() {
61 return [
62 [ 'hidden1', [ 'read' ] ],
63 [ [ 'hidden1', 'hidden2', 'hidden3' ], [ 'read', 'autoconfirmed' ] ],
64 [ [ 'normal1', 'normal2' ], [ 'edit', 'create' ] ],
68 /**
69 * @dataProvider provideGrantsAreValid
70 * @covers MWGrants::grantsAreValid
71 * @param array $grants
72 * @param bool $valid
74 public function testGrantsAreValid( $grants, $valid ) {
75 $this->assertSame( $valid, MWGrants::grantsAreValid( $grants ) );
78 public static function provideGrantsAreValid() {
79 return [
80 [ [ 'hidden1', 'hidden2' ], true ],
81 [ [ 'hidden1', 'hidden3' ], false ],
85 /**
86 * @dataProvider provideGetGrantGroups
87 * @covers MWGrants::getGrantGroups
88 * @param array|null $grants
89 * @param array $expect
91 public function testGetGrantGroups( $grants, $expect ) {
92 $this->assertSame( $expect, MWGrants::getGrantGroups( $grants ) );
95 public static function provideGetGrantGroups() {
96 return [
97 [ null, [
98 'hidden' => [ 'hidden1', 'hidden2' ],
99 'normal-group' => [ 'normal' ],
100 'other' => [ 'normal2' ],
101 'admin' => [ 'admin' ],
102 ] ],
103 [ [ 'hidden1', 'normal' ], [
104 'hidden' => [ 'hidden1' ],
105 'normal-group' => [ 'normal' ],
106 ] ],
111 * @covers MWGrants::getHiddenGrants
113 public function testGetHiddenGrants() {
114 $this->assertSame( [ 'hidden1', 'hidden2' ], MWGrants::getHiddenGrants() );