Merge "mw.Upload.BookletLayout: Don't explode when the API call fails with 'exception'"
[lhc/web/wiklou.git] / tests / phpunit / includes / utils / MWGrantsTest.php
1 <?php
2 class MWGrantsTest extends MediaWikiTestCase {
3
4 protected function setUp() {
5 parent::setUp();
6
7 $this->setMwGlobals( array(
8 'wgGrantPermissions' => array(
9 'hidden1' => array( 'read' => true, 'autoconfirmed' => false ),
10 'hidden2' => array( 'autoconfirmed' => true ),
11 'normal' => array( 'edit' => true ),
12 'normal2' => array( 'edit' => true, 'create' => true ),
13 'admin' => array( 'protect' => true, 'delete' => true ),
14 ),
15 'wgGrantPermissionGroups' => array(
16 'hidden1' => 'hidden',
17 'hidden2' => 'hidden',
18 'normal' => 'normal-group',
19 'admin' => 'admin',
20 ),
21 ) );
22 }
23
24 /**
25 * @covers MWGrants::getValidGrants
26 */
27 public function testGetValidGrants() {
28 $this->assertSame(
29 array( 'hidden1', 'hidden2', 'normal', 'normal2', 'admin' ),
30 MWGrants::getValidGrants()
31 );
32 }
33
34 /**
35 * @covers MWGrants::getRightsByGrant
36 */
37 public function testGetRightsByGrant() {
38 $this->assertSame(
39 array(
40 'hidden1' => array( 'read' ),
41 'hidden2' => array( 'autoconfirmed' ),
42 'normal' => array( 'edit' ),
43 'normal2' => array( 'edit', 'create' ),
44 'admin' => array( 'protect', 'delete' ),
45 ),
46 MWGrants::getRightsByGrant()
47 );
48 }
49
50 /**
51 * @dataProvider provideGetGrantRights
52 * @covers MWGrants::getGrantRights
53 * @param array|string $grants
54 * @param array $rights
55 */
56 public function testGetGrantRights( $grants, $rights ) {
57 $this->assertSame( $rights, MWGrants::getGrantRights( $grants ) );
58 }
59
60 public static function provideGetGrantRights() {
61 return array(
62 array( 'hidden1', array( 'read' ) ),
63 array( array( 'hidden1', 'hidden2', 'hidden3' ), array( 'read', 'autoconfirmed' ) ),
64 array( array( 'normal1', 'normal2' ), array( 'edit', 'create' ) ),
65 );
66 }
67
68 /**
69 * @dataProvider provideGrantsAreValid
70 * @covers MWGrants::grantsAreValid
71 * @param array $grants
72 * @param bool $valid
73 */
74 public function testGrantsAreValid( $grants, $valid ) {
75 $this->assertSame( $valid, MWGrants::grantsAreValid( $grants ) );
76 }
77
78 public static function provideGrantsAreValid() {
79 return array(
80 array( array( 'hidden1', 'hidden2' ), true ),
81 array( array( 'hidden1', 'hidden3' ), false ),
82 );
83 }
84
85 /**
86 * @dataProvider provideGetGrantGroups
87 * @covers MWGrants::getGrantGroups
88 * @param array|null $grants
89 * @param array $expect
90 */
91 public function testGetGrantGroups( $grants, $expect ) {
92 $this->assertSame( $expect, MWGrants::getGrantGroups( $grants ) );
93 }
94
95 public static function provideGetGrantGroups() {
96 return array(
97 array( null, array(
98 'hidden' => array( 'hidden1', 'hidden2' ),
99 'normal-group' => array( 'normal' ),
100 'other' => array( 'normal2' ),
101 'admin' => array( 'admin' ),
102 ) ),
103 array( array( 'hidden1', 'normal' ), array(
104 'hidden' => array( 'hidden1' ),
105 'normal-group' => array( 'normal' ),
106 ) ),
107 );
108 }
109
110 /**
111 * @covers MWGrants::getHiddenGrants
112 */
113 public function testGetHiddenGrants() {
114 $this->assertSame( array( 'hidden1', 'hidden2' ), MWGrants::getHiddenGrants() );
115 }
116
117 }