MediaWiki  1.30.0
MWGrantsTest.php
Go to the documentation of this file.
1 <?php
3 
4  protected function setUp() {
5  parent::setUp();
6 
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 ],
14  ],
15  'wgGrantPermissionGroups' => [
16  'hidden1' => 'hidden',
17  'hidden2' => 'hidden',
18  'normal' => 'normal-group',
19  'admin' => 'admin',
20  ],
21  ] );
22  }
23 
27  public function testGetValidGrants() {
28  $this->assertSame(
29  [ 'hidden1', 'hidden2', 'normal', 'normal2', 'admin' ],
31  );
32  }
33 
37  public function testGetRightsByGrant() {
38  $this->assertSame(
39  [
40  'hidden1' => [ 'read' ],
41  'hidden2' => [ 'autoconfirmed' ],
42  'normal' => [ 'edit' ],
43  'normal2' => [ 'edit', 'create' ],
44  'admin' => [ 'protect', 'delete' ],
45  ],
47  );
48  }
49 
56  public function testGetGrantRights( $grants, $rights ) {
57  $this->assertSame( $rights, MWGrants::getGrantRights( $grants ) );
58  }
59 
60  public static function provideGetGrantRights() {
61  return [
62  [ 'hidden1', [ 'read' ] ],
63  [ [ 'hidden1', 'hidden2', 'hidden3' ], [ 'read', 'autoconfirmed' ] ],
64  [ [ 'normal1', 'normal2' ], [ 'edit', 'create' ] ],
65  ];
66  }
67 
74  public function testGrantsAreValid( $grants, $valid ) {
75  $this->assertSame( $valid, MWGrants::grantsAreValid( $grants ) );
76  }
77 
78  public static function provideGrantsAreValid() {
79  return [
80  [ [ 'hidden1', 'hidden2' ], true ],
81  [ [ 'hidden1', 'hidden3' ], false ],
82  ];
83  }
84 
91  public function testGetGrantGroups( $grants, $expect ) {
92  $this->assertSame( $expect, MWGrants::getGrantGroups( $grants ) );
93  }
94 
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  ] ],
107  ];
108  }
109 
113  public function testGetHiddenGrants() {
114  $this->assertSame( [ 'hidden1', 'hidden2' ], MWGrants::getHiddenGrants() );
115  }
116 
117 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MWGrants\getGrantRights
static getGrantRights( $grants)
Fetch the rights allowed by a set of grants.
Definition: MWGrants.php:107
MWGrantsTest\provideGrantsAreValid
static provideGrantsAreValid()
Definition: MWGrantsTest.php:78
MWGrantsTest\testGetGrantGroups
testGetGrantGroups( $grants, $expect)
provideGetGrantGroups MWGrants::getGrantGroups
Definition: MWGrantsTest.php:91
MWGrantsTest\provideGetGrantRights
static provideGetGrantRights()
Definition: MWGrantsTest.php:60
MWGrants\getHiddenGrants
static getHiddenGrants()
Get the list of grants that are hidden and should always be granted.
Definition: MWGrants.php:159
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MWGrantsTest\testGetRightsByGrant
testGetRightsByGrant()
MWGrants::getRightsByGrant.
Definition: MWGrantsTest.php:37
MWGrantsTest\testGetGrantRights
testGetGrantRights( $grants, $rights)
provideGetGrantRights MWGrants::getGrantRights
Definition: MWGrantsTest.php:56
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
MWGrantsTest\testGrantsAreValid
testGrantsAreValid( $grants, $valid)
provideGrantsAreValid MWGrants::grantsAreValid
Definition: MWGrantsTest.php:74
MWGrantsTest\testGetValidGrants
testGetValidGrants()
MWGrants::getValidGrants.
Definition: MWGrantsTest.php:27
MWGrants\getValidGrants
static getValidGrants()
List all known grants.
Definition: MWGrants.php:31
MWGrants\grantsAreValid
static grantsAreValid(array $grants)
Test that all grants in the list are known.
Definition: MWGrants.php:124
MWGrantsTest\setUp
setUp()
Definition: MWGrantsTest.php:4
MWGrants\getGrantGroups
static getGrantGroups( $grantsFilter=null)
Divide the grants into groups.
Definition: MWGrants.php:133
MWGrantsTest\testGetHiddenGrants
testGetHiddenGrants()
MWGrants::getHiddenGrants.
Definition: MWGrantsTest.php:113
MWGrants\getRightsByGrant
static getRightsByGrant()
Map all grants to corresponding user rights.
Definition: MWGrants.php:41
MWGrantsTest
Definition: MWGrantsTest.php:2
MWGrantsTest\provideGetGrantGroups
static provideGetGrantGroups()
Definition: MWGrantsTest.php:95
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1965