26 $wgAddGroups[
'bureaucrat'] = $add;
30 $wgRemoveGroups[
'bureaucrat'] = $remove;
49 $expectedGroups =
'sysop', array
$params = [],
User $user =
null
51 $expectedGroups = (
array)$expectedGroups;
52 $params[
'action'] =
'userrights';
58 $this->assertTrue( TestUserRegistry::isMutable( $user ),
59 'Immutable user passed to doSuccessfulRightsChange!' );
62 $params[
'user'] = $user->getName();
70 $user->clearInstanceCache();
71 $this->assertSame( $expectedGroups, $user->getGroups() );
73 $this->assertArrayNotHasKey(
'warnings',
$res[0] );
86 $expectedException, array
$params = [],
User $user =
null
88 $params[
'action'] =
'userrights';
90 $this->setExpectedException( ApiUsageException::class, $expectedException );
100 $this->assertTrue( TestUserRegistry::isMutable( $user ),
101 'Immutable user passed to doFailedRightsChange!' );
104 $params[
'user'] = $user->getName();
109 $expectedGroups = $user->getGroups();
114 $user->clearInstanceCache();
115 $this->assertSame( $expectedGroups, $user->getGroups() );
142 $block =
new Block( [
'address' => $user,
'by' => $user->getId() ] );
149 $user->clearInstanceCache();
155 [
'bureaucrat',
'sysop' ],
156 [
'add' =>
'bureaucrat|sysop' ]
162 '2 expiry timestamps were provided where 3 were needed.',
163 [
'add' =>
'sysop|bureaucrat|bot',
'expiry' =>
'infinity|tomorrow' ]
169 '3 expiry timestamps were provided where 2 were needed.',
170 [
'add' =>
'sysop|bureaucrat',
'expiry' =>
'infinity|tomorrow|never' ]
180 'Invalid expiry time "foo".',
181 [
'add' =>
'sysop|bureaucrat',
'expiry' =>
'foo|bar' ]
196 [
'change_tag',
'logging' ],
199 'ct_log_id = log_id',
200 'log_namespace' => NS_USER,
201 'log_title' => strtr( $user->getName(),
' ',
'_' )
214 $wgGroupPermissions[
'user'][
'applychangetags'] =
false;
217 'You do not have permission to apply change tags along with your changes.',
218 [
'tags' =>
'custom tag' ]
224 'There is no user by the name "Nonexistent user". Check your spelling.',
225 [
'user' =>
'Nonexistent user' ]
233 $token = $sysop->getEditToken( $user->getName() );
236 'action' =>
'userrights',
237 'user' => $user->getName(),
242 $user->clearInstanceCache();
243 $this->assertSame( [
'sysop' ], $user->getGroups() );
245 $this->assertArrayNotHasKey(
'warnings',
$res[0] );
260 $token = $sysop->getEditToken(
'userrights' );
263 'action' =>
'userrights',
264 'user' => $user->getName(),
269 $mockUserRightsPage = $this->getMockBuilder( UserrightsPage::class )
270 ->setMethods( [
'canProcessExpiries' ] )
272 $mockUserRightsPage->method(
'canProcessExpiries' )->willReturn( $canProcessExpiries );
274 $mockApi = $this->getMockBuilder( ApiUserrights::class )
275 ->setConstructorArgs( [ $main,
'userrights' ] )
276 ->setMethods( [
'getUserRightsPage' ] )
278 $mockApi->method(
'getUserRightsPage' )->willReturn( $mockUserRightsPage );
285 $this->assertArrayHasKey(
'expiry', $mock1->getAllowedParams() );
288 $this->assertArrayNotHasKey(
'expiry', $mock2->getAllowedParams() );
301 array $permissions =
null, array $groupsToChange, array $expectedGroups
303 if ( $permissions !==
null ) {
308 'add' => implode(
'|', $groupsToChange[0] ),
309 'remove' => implode(
'|', $groupsToChange[1] ),
324 ],
'Add with only remove permission' => [
328 ],
'Add with global remove permission' => [
332 ],
'Simple remove' => [
336 ],
'Remove with only add permission' => [
340 ],
'Remove with global add permission' => [
344 ],
'Add and remove same new group' => [
346 [ [
'sysop' ], [
'sysop' ] ],
350 ],
'Add and remove same existing group' => [
352 [ [
'bot' ], [
'bot' ] ],
$wgAddGroups
$wgAddGroups and $wgRemoveGroups can be used to give finer control over who can assign which groups a...
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
$wgGroupPermissions['sysop']['replacetext']
This is the main API class, used for both external and internal processing.
doApiRequestWithToken(array $params, array $session=null, User $user=null, $tokenType='auto')
Convenience function to access the token parameter of doApiRequest() more succinctly.
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
testAddAndRemoveGroups(array $permissions=null, array $groupsToChange, array $expectedGroups)
Tests adding and removing various groups with various permissions.
doFailedRightsChange( $expectedException, array $params=[], User $user=null)
Perform an API userrights request that's expected to fail.
addAndRemoveGroupsProvider()
testBlockedWithUserrights()
doSuccessfulRightsChange( $expectedGroups='sysop', array $params=[], User $user=null)
Perform an API userrights request that's expected to be successful.
testMultipleInvalidExpiries()
setPermissions( $add=[], $remove=[])
Unsets $wgGroupPermissions['bureaucrat']['userrights'], and sets $wgAddGroups['bureaucrat'] and $wgRe...
testBlockedWithoutUserrights()
getMockForProcessingExpiries( $canProcessExpiries)
Helper for testCanProcessExpiries that returns a mock ApiUserrights that either can or cannot process...
testWithoutTagPermission()
WebRequest clone which takes values from a provided array.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
the array() calling protocol came about after MediaWiki 1.4rc1.
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