namespace MediaWiki\Tests\Permissions;
use Action;
-use Block;
+use FauxRequest;
+use MediaWiki\Session\SessionId;
+use MediaWiki\Session\TestUtils;
use MediaWikiLangTestCase;
use RequestContext;
+use stdClass;
use Title;
use User;
+use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\Restriction\NamespaceRestriction;
use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\Block\SystemBlock;
use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionManager;
+use Wikimedia\ScopedCallback;
+use Wikimedia\TestingAccessWrapper;
/**
* @group Database
*/
protected $user, $anonUser, $userUser, $altUser;
- /**
- * @var PermissionManager
- */
- protected $permissionManager;
-
/** Constant for self::testIsBlockedFrom */
const USER_TALK_PAGE = '<user talk page>';
'wgNamespaceProtection' => [
NS_MEDIAWIKI => 'editinterface',
],
+ 'wgRevokePermissions' => [
+ 'formertesters' => [
+ 'runtest' => true
+ ]
+ ],
+ 'wgAvailableRights' => [
+ 'test',
+ 'runtest',
+ 'writetest',
+ 'nukeworld',
+ 'modifytest',
+ 'editmyoptions'
+ ]
] );
+
+ $this->setGroupPermissions( 'unittesters', 'test', true );
+ $this->setGroupPermissions( 'unittesters', 'runtest', true );
+ $this->setGroupPermissions( 'unittesters', 'writetest', false );
+ $this->setGroupPermissions( 'unittesters', 'nukeworld', false );
+
+ $this->setGroupPermissions( 'testwriters', 'test', true );
+ $this->setGroupPermissions( 'testwriters', 'writetest', true );
+ $this->setGroupPermissions( 'testwriters', 'modifytest', true );
+
+ $this->setGroupPermissions( '*', 'editmyoptions', true );
+
// Without this testUserBlock will use a non-English context on non-English MediaWiki
// installations (because of how Title::checkUserBlock is implemented) and fail.
RequestContext::resetMain();
$this->user = $this->userUser;
}
- $this->permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
-
- $this->overrideMwServices();
+ $this->resetServices();
}
- protected function setUserPerm( $perm ) {
- // Setting member variables is evil!!!
-
- if ( is_array( $perm ) ) {
- $this->user->mRights = $perm;
- } else {
- $this->user->mRights = [ $perm ];
- }
+ public function tearDown() {
+ parent::tearDown();
+ $this->restoreMwServices();
}
protected function setTitle( $ns, $title = "Main_Page" ) {
} else {
$this->user = $this->altUser;
}
+ $this->resetServices();
}
/**
$this->setUser( 'anon' );
$this->setTitle( NS_TALK );
- $this->setUserPerm( "createtalk" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "createtalk" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [], $res );
$this->setTitle( NS_TALK );
- $this->setUserPerm( "createpage" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "createpage" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [ [ "nocreatetext" ] ], $res );
$this->setTitle( NS_TALK );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [ [ 'nocreatetext' ] ], $res );
$this->setTitle( NS_MAIN );
- $this->setUserPerm( "createpage" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "createpage" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [], $res );
$this->setTitle( NS_MAIN );
- $this->setUserPerm( "createtalk" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "createtalk" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [ [ 'nocreatetext' ] ], $res );
$this->setUser( $this->userName );
$this->setTitle( NS_TALK );
- $this->setUserPerm( "createtalk" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "createtalk" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [], $res );
$this->setTitle( NS_TALK );
- $this->setUserPerm( "createpage" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "createpage" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
$this->setTitle( NS_TALK );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
$this->setTitle( NS_MAIN );
- $this->setUserPerm( "createpage" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "createpage" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [], $res );
$this->setTitle( NS_MAIN );
- $this->setUserPerm( "createtalk" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "createtalk" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
$this->setTitle( NS_MAIN );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title );
$this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
$this->setUser( 'anon' );
$this->setTitle( NS_USER, $this->userName . '' );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'cant-move-user-page' ], [ 'movenologintext' ] ], $res );
$this->setTitle( NS_USER, $this->userName . '/subpage' );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
$this->setTitle( NS_USER, $this->userName . '' );
- $this->setUserPerm( "move-rootuserpages" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "move-rootuserpages" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
$this->setTitle( NS_USER, $this->userName . '/subpage' );
- $this->setUserPerm( "move-rootuserpages" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "move-rootuserpages" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
$this->setTitle( NS_USER, $this->userName . '' );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'cant-move-user-page' ], [ 'movenologintext' ] ], $res );
$this->setTitle( NS_USER, $this->userName . '/subpage' );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
$this->setTitle( NS_USER, $this->userName . '' );
- $this->setUserPerm( "move-rootuserpages" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "move-rootuserpages" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
$this->setTitle( NS_USER, $this->userName . '/subpage' );
- $this->setUserPerm( "move-rootuserpages" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "move-rootuserpages" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
$this->setUser( $this->userName );
$this->setTitle( NS_FILE, "img.png" );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ], $res );
$this->setTitle( NS_FILE, "img.png" );
- $this->setUserPerm( "movefile" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "movefile" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenotallowed' ] ], $res );
$this->setUser( 'anon' );
$this->setTitle( NS_FILE, "img.png" );
- $this->setUserPerm( "" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenotallowedfile' ], [ 'movenologintext' ] ], $res );
$this->setTitle( NS_FILE, "img.png" );
- $this->setUserPerm( "movefile" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "movefile" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title );
$this->assertEquals( [ [ 'movenologintext' ] ], $res );
$this->setUser( $this->userName );
- $this->setUserPerm( "move" );
- $this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
+ // $this->setUserPerm( "move" );
+ $this->runGroupPermissions( 'move', 'move', [ [ 'movenotallowedfile' ] ] );
- $this->setUserPerm( "" );
+ // $this->setUserPerm( "" );
$this->runGroupPermissions(
+ '',
'move',
[ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ]
);
$this->setUser( 'anon' );
- $this->setUserPerm( "move" );
- $this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
+ //$this->setUserPerm( "move" );
+ $this->runGroupPermissions( 'move', 'move', [ [ 'movenotallowedfile' ] ] );
- $this->setUserPerm( "" );
+ // $this->setUserPerm( "" );
$this->runGroupPermissions(
+ '',
'move',
[ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ],
[ [ 'movenotallowedfile' ], [ 'movenologintext' ] ]
$this->setTitle( NS_MAIN );
$this->setUser( 'anon' );
- $this->setUserPerm( "move" );
- $this->runGroupPermissions( 'move', [] );
+ // $this->setUserPerm( "move" );
+ $this->runGroupPermissions( 'move', 'move', [] );
- $this->setUserPerm( "" );
- $this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ],
+ // $this->setUserPerm( "" );
+ $this->runGroupPermissions( '', 'move', [ [ 'movenotallowed' ] ],
[ [ 'movenologintext' ] ] );
$this->setUser( $this->userName );
- $this->setUserPerm( "" );
- $this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ] );
+ // $this->setUserPerm( "" );
+ $this->runGroupPermissions( '', 'move', [ [ 'movenotallowed' ] ] );
- $this->setUserPerm( "move" );
- $this->runGroupPermissions( 'move', [] );
+ //$this->setUserPerm( "move" );
+ $this->runGroupPermissions( 'move', 'move', [] );
$this->setUser( 'anon' );
- $this->setUserPerm( 'move' );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, 'move' );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title );
$this->assertEquals( [], $res );
- $this->setUserPerm( '' );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, '' );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title );
$this->assertEquals( [ [ 'movenotallowed' ] ], $res );
}
$this->setTitle( NS_USER );
$this->setUser( $this->userName );
- $this->setUserPerm( [ "move", "move-rootuserpages" ] );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, [ "move", "move-rootuserpages" ] );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title );
$this->assertEquals( [], $res );
- $this->setUserPerm( "move" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "move" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title );
$this->assertEquals( [ [ 'cant-move-to-user-page' ] ], $res );
$this->setUser( 'anon' );
- $this->setUserPerm( [ "move", "move-rootuserpages" ] );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, [ "move", "move-rootuserpages" ] );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title );
$this->assertEquals( [], $res );
$this->setTitle( NS_USER, "User/subpage" );
- $this->setUserPerm( [ "move", "move-rootuserpages" ] );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, [ "move", "move-rootuserpages" ] );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title );
$this->assertEquals( [], $res );
- $this->setUserPerm( "move" );
- $res = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, "move" );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title );
$this->assertEquals( [], $res );
];
foreach ( [ "edit", "protect", "" ] as $action ) {
- $this->setUserPerm( null );
+ $this->overrideUserPermissions( $this->user );
$this->assertEquals( $check[$action][0],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, true ) );
$this->assertEquals( $check[$action][0],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, 'full' ) );
$this->assertEquals( $check[$action][0],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, 'secure' ) );
global $wgGroupPermissions;
$old = $wgGroupPermissions;
$wgGroupPermissions = [];
+ $this->resetServices();
$this->assertEquals( $check[$action][1],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, true ) );
$this->assertEquals( $check[$action][1],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, 'full' ) );
$this->assertEquals( $check[$action][1],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, 'secure' ) );
$wgGroupPermissions = $old;
+ $this->resetServices();
- $this->setUserPerm( $action );
+ $this->overrideUserPermissions( $this->user, $action );
$this->assertEquals( $check[$action][2],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, true ) );
$this->assertEquals( $check[$action][2],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, 'full' ) );
$this->assertEquals( $check[$action][2],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title, 'secure' ) );
- $this->setUserPerm( $action );
+ $this->overrideUserPermissions( $this->user, $action );
$this->assertEquals( $check[$action][3],
- $this->permissionManager->userCan( $action, $this->user, $this->title, true ) );
+ MediaWikiServices::getInstance()->getPermissionManager()
+ ->userCan( $action, $this->user, $this->title, true ) );
$this->assertEquals( $check[$action][3],
- $this->permissionManager->userCan( $action, $this->user, $this->title,
+ MediaWikiServices::getInstance()->getPermissionManager()
+ ->userCan( $action, $this->user, $this->title,
PermissionManager::RIGOR_QUICK ) );
# count( User::getGroupsWithPermissions( $action ) ) < 1
}
}
- protected function runGroupPermissions( $action, $result, $result2 = null ) {
+ protected function runGroupPermissions( $perm, $action, $result, $result2 = null ) {
global $wgGroupPermissions;
if ( $result2 === null ) {
$wgGroupPermissions['autoconfirmed']['move'] = false;
$wgGroupPermissions['user']['move'] = false;
- $res = $this->permissionManager
+ $this->resetServices();
+ $this->overrideUserPermissions( $this->user, $perm );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title );
$this->assertEquals( $result, $res );
$wgGroupPermissions['autoconfirmed']['move'] = true;
$wgGroupPermissions['user']['move'] = false;
- $res = $this->permissionManager
+ $this->resetServices();
+ $this->overrideUserPermissions( $this->user, $perm );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title );
$this->assertEquals( $result2, $res );
$wgGroupPermissions['autoconfirmed']['move'] = true;
$wgGroupPermissions['user']['move'] = true;
- $res = $this->permissionManager
+ $this->resetServices();
+ $this->overrideUserPermissions( $this->user, $perm );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title );
$this->assertEquals( $result2, $res );
$wgGroupPermissions['autoconfirmed']['move'] = false;
$wgGroupPermissions['user']['move'] = true;
- $res = $this->permissionManager
+ $this->resetServices();
+ $this->overrideUserPermissions( $this->user, $perm );
+ $res = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( $action, $this->user, $this->title );
$this->assertEquals( $result2, $res );
}
$this->setTitle( NS_SPECIAL );
$this->assertEquals( [ [ 'badaccess-group0' ], [ 'ns-specialprotected' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
$this->setTitle( NS_MAIN );
- $this->setUserPerm( 'bogus' );
+ $this->overrideUserPermissions( $this->user, 'bogus' );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
$this->setTitle( NS_MAIN );
- $this->setUserPerm( '' );
+ $this->overrideUserPermissions( $this->user, '' );
$this->assertEquals( [ [ 'badaccess-group0' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
$wgNamespaceProtection[NS_USER] = [ 'bogus' ];
$this->setTitle( NS_USER );
- $this->setUserPerm( '' );
+ $this->overrideUserPermissions( $this->user, '' );
$this->assertEquals( [ [ 'badaccess-group0' ],
[ 'namespaceprotected', 'User', 'bogus' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
$this->setTitle( NS_MEDIAWIKI );
- $this->setUserPerm( 'bogus' );
+ $this->overrideUserPermissions( $this->user, 'bogus' );
$this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
$this->setTitle( NS_MEDIAWIKI );
- $this->setUserPerm( 'bogus' );
+ $this->overrideUserPermissions( $this->user, 'bogus' );
$this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
$wgNamespaceProtection = null;
- $this->setUserPerm( 'bogus' );
+ $this->overrideUserPermissions( $this->user, 'bogus' );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
$this->assertEquals( true,
- $this->permissionManager->userCan( 'bogus', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()
+ ->userCan( 'bogus', $this->user, $this->title ) );
- $this->setUserPerm( '' );
+ $this->overrideUserPermissions( $this->user, '' );
$this->assertEquals( [ [ 'badaccess-group0' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'bogus', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()
+ ->userCan( 'bogus', $this->user, $this->title ) );
}
/**
$resultUserJs,
$resultPatrol
) {
- $this->setUserPerm( '' );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title );
$this->assertEquals( $resultNone, $result );
- $this->setUserPerm( 'editmyusercss' );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, 'editmyusercss' );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title );
$this->assertEquals( $resultMyCss, $result );
- $this->setUserPerm( 'editmyuserjson' );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, 'editmyuserjson' );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title );
$this->assertEquals( $resultMyJson, $result );
- $this->setUserPerm( 'editmyuserjs' );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, 'editmyuserjs' );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title );
$this->assertEquals( $resultMyJs, $result );
- $this->setUserPerm( 'editusercss' );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, 'editusercss' );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title );
$this->assertEquals( $resultUserCss, $result );
- $this->setUserPerm( 'edituserjson' );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, 'edituserjson' );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title );
$this->assertEquals( $resultUserJson, $result );
- $this->setUserPerm( 'edituserjs' );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, 'edituserjs' );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title );
$this->assertEquals( $resultUserJs, $result );
- $this->setUserPerm( '' );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'patrol', $this->user, $this->title );
$this->assertEquals( reset( $resultPatrol[0] ), reset( $result[0] ) );
- $this->setUserPerm( [ 'edituserjs', 'edituserjson', 'editusercss' ] );
- $result = $this->permissionManager
+ $this->overrideUserPermissions( $this->user, [ 'edituserjs', 'edituserjson', 'editusercss' ] );
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title );
$this->assertEquals( [ [ 'badaccess-group0' ] ], $result );
}
$this->setTitle( NS_MAIN );
$this->title->mRestrictionsLoaded = true;
- $this->setUserPerm( "edit" );
+ $this->overrideUserPermissions( $this->user, "edit" );
$this->title->mRestrictions = [ "bogus" => [ 'bogus', "sysop", "protect", "" ] ];
$this->assertEquals( [],
- $this->permissionManager->getPermissionErrors( 'edit',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()
+ ->getPermissionErrors( 'edit', $this->user, $this->title ) );
$this->assertEquals( true,
- $this->permissionManager->userCan( 'edit', $this->user, $this->title,
- PermissionManager::RIGOR_QUICK ) );
+ MediaWikiServices::getInstance()->getPermissionManager()
+ ->userCan( 'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
$this->title->mRestrictions = [ "edit" => [ 'bogus', "sysop", "protect", "" ],
"bogus" => [ 'bogus', "sysop", "protect", "" ] ];
[ 'protectedpagetext', 'bogus', 'bogus' ],
[ 'protectedpagetext', 'editprotected', 'bogus' ],
[ 'protectedpagetext', 'protect', 'bogus' ] ],
- $this->permissionManager->getPermissionErrors( 'bogus',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'bogus', $this->user, $this->title ) );
$this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
[ 'protectedpagetext', 'editprotected', 'edit' ],
[ 'protectedpagetext', 'protect', 'edit' ] ],
- $this->permissionManager->getPermissionErrors( 'edit',
- $this->user, $this->title ) );
- $this->setUserPerm( "" );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'edit', $this->user, $this->title ) );
+ $this->overrideUserPermissions( $this->user );
$this->assertEquals( [ [ 'badaccess-group0' ],
[ 'protectedpagetext', 'bogus', 'bogus' ],
[ 'protectedpagetext', 'editprotected', 'bogus' ],
[ 'protectedpagetext', 'protect', 'bogus' ] ],
- $this->permissionManager->getPermissionErrors( 'bogus',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'bogus', $this->user, $this->title ) );
$this->assertEquals( [ [ 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ],
[ 'protectedpagetext', 'bogus', 'edit' ],
[ 'protectedpagetext', 'editprotected', 'edit' ],
[ 'protectedpagetext', 'protect', 'edit' ] ],
- $this->permissionManager->getPermissionErrors( 'edit',
- $this->user, $this->title ) );
- $this->setUserPerm( [ "edit", "editprotected" ] );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'edit', $this->user, $this->title ) );
+ $this->overrideUserPermissions( $this->user, [ "edit", "editprotected" ] );
$this->assertEquals( [ [ 'badaccess-group0' ],
[ 'protectedpagetext', 'bogus', 'bogus' ],
[ 'protectedpagetext', 'protect', 'bogus' ] ],
- $this->permissionManager->getPermissionErrors( 'bogus',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'bogus', $this->user, $this->title ) );
$this->assertEquals( [
[ 'protectedpagetext', 'bogus', 'edit' ],
[ 'protectedpagetext', 'protect', 'edit' ] ],
- $this->permissionManager->getPermissionErrors( 'edit',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'edit', $this->user, $this->title ) );
$this->title->mCascadeRestriction = true;
- $this->setUserPerm( "edit" );
+ $this->overrideUserPermissions( $this->user, "edit" );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'bogus', $this->user, $this->title,
- PermissionManager::RIGOR_QUICK ) );
+ MediaWikiServices::getInstance()->getPermissionManager()
+ ->userCan( 'bogus', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'edit', $this->user, $this->title,
- PermissionManager::RIGOR_QUICK ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
$this->assertEquals( [ [ 'badaccess-group0' ],
[ 'protectedpagetext', 'bogus', 'bogus' ],
[ 'protectedpagetext', 'editprotected', 'bogus' ],
[ 'protectedpagetext', 'protect', 'bogus' ] ],
- $this->permissionManager->getPermissionErrors( 'bogus',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'bogus', $this->user, $this->title ) );
$this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
[ 'protectedpagetext', 'editprotected', 'edit' ],
[ 'protectedpagetext', 'protect', 'edit' ] ],
- $this->permissionManager->getPermissionErrors( 'edit',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'edit', $this->user, $this->title ) );
- $this->setUserPerm( [ "edit", "editprotected" ] );
+ $this->overrideUserPermissions( $this->user, [ "edit", "editprotected" ] );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'bogus', $this->user, $this->title,
- PermissionManager::RIGOR_QUICK ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'bogus', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'edit', $this->user, $this->title,
- PermissionManager::RIGOR_QUICK ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
$this->assertEquals( [ [ 'badaccess-group0' ],
[ 'protectedpagetext', 'bogus', 'bogus' ],
[ 'protectedpagetext', 'protect', 'bogus' ],
[ 'protectedpagetext', 'protect', 'bogus' ] ],
- $this->permissionManager->getPermissionErrors( 'bogus',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'bogus', $this->user, $this->title ) );
$this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
[ 'protectedpagetext', 'protect', 'edit' ],
[ 'protectedpagetext', 'protect', 'edit' ] ],
- $this->permissionManager->getPermissionErrors( 'edit',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'edit', $this->user, $this->title ) );
}
/**
*/
public function testCascadingSourcesRestrictions() {
$this->setTitle( NS_MAIN, "test page" );
- $this->setUserPerm( [ "edit", "bogus" ] );
+ $this->overrideUserPermissions( $this->user, [ "edit", "bogus" ] );
$this->title->mCascadeSources = [
Title::makeTitle( NS_MAIN, "Bogus" ),
];
$this->assertEquals( false,
- $this->permissionManager->userCan( 'bogus', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'bogus', $this->user, $this->title ) );
$this->assertEquals( [
[ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ],
[ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ],
[ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ] ],
- $this->permissionManager->getPermissionErrors( 'bogus', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'bogus', $this->user, $this->title ) );
$this->assertEquals( true,
- $this->permissionManager->userCan( 'edit', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'edit', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager->getPermissionErrors( 'edit', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'edit', $this->user, $this->title ) );
}
/**
* @covers \MediaWiki\Permissions\PermissionManager::checkActionPermissions
*/
public function testActionPermissions() {
- $this->setUserPerm( [ "createpage" ] );
+ $this->overrideUserPermissions( $this->user, [ "createpage" ] );
$this->setTitle( NS_MAIN, "test page" );
$this->title->mTitleProtection['permission'] = '';
$this->title->mTitleProtection['user'] = $this->user->getId();
$this->title->mCascadeRestriction = false;
$this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title ) );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'create', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'create', $this->user, $this->title ) );
$this->title->mTitleProtection['permission'] = 'editprotected';
- $this->setUserPerm( [ 'createpage', 'protect' ] );
+ $this->overrideUserPermissions( $this->user, [ 'createpage', 'protect' ] );
$this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title ) );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'create', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'create', $this->user, $this->title ) );
- $this->setUserPerm( [ 'createpage', 'editprotected' ] );
+ $this->overrideUserPermissions( $this->user, [ 'createpage', 'editprotected' ] );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title ) );
$this->assertEquals( true,
- $this->permissionManager->userCan( 'create', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'create', $this->user, $this->title ) );
- $this->setUserPerm( [ 'createpage' ] );
+ $this->overrideUserPermissions( $this->user, [ 'createpage' ] );
$this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'create', $this->user, $this->title ) );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'create', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'create', $this->user, $this->title ) );
$this->setTitle( NS_MEDIA, "test page" );
- $this->setUserPerm( [ "move" ] );
+ $this->overrideUserPermissions( $this->user, [ "move" ] );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'move', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'move', $this->user, $this->title ) );
$this->assertEquals( [ [ 'immobile-source-namespace', 'Media' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title ) );
$this->setTitle( NS_HELP, "test page" );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title ) );
$this->assertEquals( true,
- $this->permissionManager->userCan( 'move', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'move', $this->user, $this->title ) );
$this->title->mInterwiki = "no";
$this->assertEquals( [ [ 'immobile-source-page' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move', $this->user, $this->title ) );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'move', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'move', $this->user, $this->title ) );
$this->setTitle( NS_MEDIA, "test page" );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'move-target', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'move-target', $this->user, $this->title ) );
$this->assertEquals( [ [ 'immobile-target-namespace', 'Media' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title ) );
$this->setTitle( NS_HELP, "test page" );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title ) );
$this->assertEquals( true,
- $this->permissionManager->userCan( 'move-target', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'move-target', $this->user, $this->title ) );
$this->title->mInterwiki = "no";
$this->assertEquals( [ [ 'immobile-target-page' ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title ) );
$this->assertEquals( false,
- $this->permissionManager->userCan( 'move-target', $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->userCan(
+ 'move-target', $this->user, $this->title ) );
}
/**
'wgBlockDisablesLogin' => false,
] );
- $this->overrideMwServices();
- $this->permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
-
- $this->setUserPerm( [
+ $this->overrideUserPermissions( $this->user, [
'createpage',
'edit',
'move',
# $wgEmailConfirmToEdit only applies to 'edit' action
$this->assertEquals( [],
- $this->permissionManager->getPermissionErrors( 'move-target',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'move-target', $this->user, $this->title ) );
$this->assertContains( [ 'confirmedittext' ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'edit', $this->user, $this->title ) );
$this->setMwGlobals( 'wgEmailConfirmToEdit', false );
- $this->overrideMwServices();
- $this->permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+ $this->resetServices();
+ $this->overrideUserPermissions( $this->user, [
+ 'createpage',
+ 'edit',
+ 'move',
+ 'rollback',
+ 'patrol',
+ 'upload',
+ 'purge'
+ ] );
$this->assertNotContains( [ 'confirmedittext' ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'edit', $this->user, $this->title ) );
# $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
$this->assertEquals( [],
- $this->permissionManager->getPermissionErrors( 'move-target',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'move-target', $this->user, $this->title ) );
global $wgLang;
$prev = time();
$now = time() + 120;
$this->user->mBlockedby = $this->user->getId();
- $this->user->mBlock = new Block( [
+ $this->user->mBlock = new DatabaseBlock( [
'address' => '127.0.8.1',
'by' => $this->user->getId(),
'reason' => 'no reason given',
] );
$this->user->mBlock->mTimestamp = 0;
$this->assertEquals( [ [ 'autoblockedtext',
- '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
- 'Useruser', null, 'infinite', '127.0.8.1',
+ "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
+ "\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1',
$wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ] ],
- $this->permissionManager->getPermissionErrors( 'move-target',
- $this->user, $this->title ) );
+ MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors(
+ 'move-target', $this->user, $this->title ) );
- $this->assertEquals( false, $this->permissionManager
+ $this->assertEquals( false, MediaWikiServices::getInstance()->getPermissionManager()
->userCan( 'move-target', $this->user, $this->title ) );
// quickUserCan should ignore user blocks
- $this->assertEquals( true, $this->permissionManager
+ $this->assertEquals( true, MediaWikiServices::getInstance()->getPermissionManager()
->userCan( 'move-target', $this->user, $this->title,
PermissionManager::RIGOR_QUICK ) );
global $wgLocalTZoffset;
$wgLocalTZoffset = -60;
$this->user->mBlockedby = $this->user->getName();
- $this->user->mBlock = new Block( [
+ $this->user->mBlock = new DatabaseBlock( [
'address' => '127.0.8.1',
'by' => $this->user->getId(),
'reason' => 'no reason given',
'expiry' => 10,
] );
$this->assertEquals( [ [ 'blockedtext',
- '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
- 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
+ "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
+ "\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1',
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title ) );
# $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
# $user->blockedFor() == ''
] );
$errors = [ [ 'systemblockedtext',
- '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
- 'Useruser', 'test', 'infinite', '127.0.8.1',
+ "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
+ "\u{202A}Useruser\u{202C}", 'test', 'infinite', '127.0.8.1',
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'edit', $this->user, $this->title ) );
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title ) );
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'rollback', $this->user, $this->title ) );
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'patrol', $this->user, $this->title ) );
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'upload', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'purge', $this->user, $this->title ) );
// partial block message test
$this->user->mBlockedby = $this->user->getName();
- $this->user->mBlock = new Block( [
+ $this->user->mBlock = new DatabaseBlock( [
'address' => '127.0.8.1',
'by' => $this->user->getId(),
'reason' => 'no reason given',
] );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'edit', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'rollback', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'patrol', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'upload', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'purge', $this->user, $this->title ) );
$this->user->mBlock->setRestrictions( [
] );
$errors = [ [ 'blockedtext-partial',
- '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
- 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
+ "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
+ "\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1',
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'edit', $this->user, $this->title ) );
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'move-target', $this->user, $this->title ) );
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'rollback', $this->user, $this->title ) );
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'patrol', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'upload', $this->user, $this->title ) );
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'purge', $this->user, $this->title ) );
// Test no block.
$this->user->mBlock = null;
$this->assertEquals( [],
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'edit', $this->user, $this->title ) );
}
$now = time();
$this->user->mBlockedby = $this->user->getName();
- $this->user->mBlock = new Block( [
+ $this->user->mBlock = new DatabaseBlock( [
'address' => '127.0.8.1',
'by' => $this->user->getId(),
'reason' => 'no reason given',
] );
$errors = [ [ 'blockedtext',
- '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
- 'Useruser', null, 'infinite', '127.0.8.1',
+ "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
+ "\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1',
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
$this->assertEquals( $errors,
- $this->permissionManager
+ MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'tester', $this->user, $this->title ) );
}
//$this->assertSame( '', $user->blockedBy(), 'sanity check' );
//$this->assertSame( '', $user->blockedFor(), 'sanity check' );
//$this->assertFalse( (bool)$user->isHidden(), 'sanity check' );
- $this->assertFalse( $this->permissionManager
+ $this->assertFalse( MediaWikiServices::getInstance()->getPermissionManager()
->isBlockedFrom( $user, $ut ), 'sanity check' );
// Block the user
$blocker = $this->getTestSysop()->getUser();
- $block = new Block( [
+ $block = new DatabaseBlock( [
'hideName' => true,
'allowUsertalk' => false,
'reason' => 'Because',
// Clear cache and confirm it loaded the block properly
$user->clearInstanceCache();
- $this->assertInstanceOf( Block::class, $user->getBlock( false ) );
+ $this->assertInstanceOf( DatabaseBlock::class, $user->getBlock( false ) );
//$this->assertSame( $blocker->getName(), $user->blockedBy() );
//$this->assertSame( 'Because', $user->blockedFor() );
//$this->assertTrue( (bool)$user->isHidden() );
- $this->assertTrue( $this->permissionManager->isBlockedFrom( $user, $ut ) );
+ $this->assertTrue( MediaWikiServices::getInstance()->getPermissionManager()
+ ->isBlockedFrom( $user, $ut ) );
// Unblock
$block->delete();
//$this->assertSame( '', $user->blockedBy() );
//$this->assertSame( '', $user->blockedFor() );
//$this->assertFalse( (bool)$user->isHidden() );
- $this->assertFalse( $this->permissionManager->isBlockedFrom( $user, $ut ) );
+ $this->assertFalse( MediaWikiServices::getInstance()->getPermissionManager()
+ ->isBlockedFrom( $user, $ut ) );
}
/**
* @param bool $expect Expected result from User::isBlockedFrom()
* @param array $options Additional test options:
* - 'blockAllowsUTEdit': (bool, default true) Value for $wgBlockAllowsUTEdit
- * - 'allowUsertalk': (bool, default false) Passed to Block::__construct()
+ * - 'allowUsertalk': (bool, default false) Passed to DatabaseBlock::__construct()
* - 'pageRestrictions': (array|null) If non-empty, page restriction titles for the block.
*/
public function testIsBlockedFrom( $title, $expect, array $options = [] ) {
$restrictions[] = new NamespaceRestriction( 0, $ns );
}
- $block = new Block( [
+ $block = new DatabaseBlock( [
'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
'allowUsertalk' => $options['allowUsertalk'] ?? false,
'sitewide' => !$restrictions,
$block->insert();
try {
- $this->assertSame( $expect, $this->permissionManager->isBlockedFrom( $user, $title ) );
+ $this->assertSame( $expect, MediaWikiServices::getInstance()->getPermissionManager()
+ ->isBlockedFrom( $user, $title ) );
} finally {
$block->delete();
}
];
}
+ /**
+ * @covers \MediaWiki\Permissions\PermissionManager::getUserPermissions
+ */
+ public function testGetUserPermissions() {
+ $user = $this->getTestUser( [ 'unittesters' ] )->getUser();
+ $rights = MediaWikiServices::getInstance()->getPermissionManager()
+ ->getUserPermissions( $user );
+ $this->assertContains( 'runtest', $rights );
+ $this->assertNotContains( 'writetest', $rights );
+ $this->assertNotContains( 'modifytest', $rights );
+ $this->assertNotContains( 'nukeworld', $rights );
+ }
+
+ /**
+ * @covers \MediaWiki\Permissions\PermissionManager::getUserPermissions
+ */
+ public function testGetUserPermissionsHooks() {
+ $user = $this->getTestUser( [ 'unittesters', 'testwriters' ] )->getUser();
+ $userWrapper = TestingAccessWrapper::newFromObject( $user );
+
+ $rights = MediaWikiServices::getInstance()->getPermissionManager()
+ ->getUserPermissions( $user );
+ $this->assertContains( 'test', $rights, 'sanity check' );
+ $this->assertContains( 'runtest', $rights, 'sanity check' );
+ $this->assertContains( 'writetest', $rights, 'sanity check' );
+ $this->assertNotContains( 'nukeworld', $rights, 'sanity check' );
+
+ // Add a hook manipluating the rights
+ $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserGetRights' => [ function ( $user, &$rights ) {
+ $rights[] = 'nukeworld';
+ $rights = array_diff( $rights, [ 'writetest' ] );
+ } ] ] );
+
+ $this->resetServices();
+ $rights = MediaWikiServices::getInstance()->getPermissionManager()
+ ->getUserPermissions( $user );
+ $this->assertContains( 'test', $rights );
+ $this->assertContains( 'runtest', $rights );
+ $this->assertNotContains( 'writetest', $rights );
+ $this->assertContains( 'nukeworld', $rights );
+
+ // Add a Session that limits rights
+ $mock = $this->getMockBuilder( stdClass::class )
+ ->setMethods( [ 'getAllowedUserRights', 'deregisterSession', 'getSessionId' ] )
+ ->getMock();
+ $mock->method( 'getAllowedUserRights' )->willReturn( [ 'test', 'writetest' ] );
+ $mock->method( 'getSessionId' )->willReturn(
+ new SessionId( str_repeat( 'X', 32 ) )
+ );
+ $session = TestUtils::getDummySession( $mock );
+ $mockRequest = $this->getMockBuilder( FauxRequest::class )
+ ->setMethods( [ 'getSession' ] )
+ ->getMock();
+ $mockRequest->method( 'getSession' )->willReturn( $session );
+ $userWrapper->mRequest = $mockRequest;
+
+ $this->resetServices();
+ $rights = MediaWikiServices::getInstance()->getPermissionManager()
+ ->getUserPermissions( $user );
+ $this->assertContains( 'test', $rights );
+ $this->assertNotContains( 'runtest', $rights );
+ $this->assertNotContains( 'writetest', $rights );
+ $this->assertNotContains( 'nukeworld', $rights );
+ }
+
+ /**
+ * @covers \MediaWiki\Permissions\PermissionManager::getGroupPermissions
+ */
+ public function testGroupPermissions() {
+ $rights = MediaWikiServices::getInstance()->getPermissionManager()
+ ->getGroupPermissions( [ 'unittesters' ] );
+ $this->assertContains( 'runtest', $rights );
+ $this->assertNotContains( 'writetest', $rights );
+ $this->assertNotContains( 'modifytest', $rights );
+ $this->assertNotContains( 'nukeworld', $rights );
+
+ $rights = MediaWikiServices::getInstance()->getPermissionManager()
+ ->getGroupPermissions( [ 'unittesters', 'testwriters' ] );
+ $this->assertContains( 'runtest', $rights );
+ $this->assertContains( 'writetest', $rights );
+ $this->assertContains( 'modifytest', $rights );
+ $this->assertNotContains( 'nukeworld', $rights );
+ }
+
+ /**
+ * @covers \MediaWiki\Permissions\PermissionManager::getGroupPermissions
+ */
+ public function testRevokePermissions() {
+ $rights = MediaWikiServices::getInstance()->getPermissionManager()
+ ->getGroupPermissions( [ 'unittesters', 'formertesters' ] );
+ $this->assertNotContains( 'runtest', $rights );
+ $this->assertNotContains( 'writetest', $rights );
+ $this->assertNotContains( 'modifytest', $rights );
+ $this->assertNotContains( 'nukeworld', $rights );
+ }
+
+ /**
+ * @dataProvider provideGetGroupsWithPermission
+ * @covers \MediaWiki\Permissions\PermissionManager::getGroupsWithPermission
+ */
+ public function testGetGroupsWithPermission( $expected, $right ) {
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
+ ->getGroupsWithPermission( $right );
+ sort( $result );
+ sort( $expected );
+
+ $this->assertEquals( $expected, $result, "Groups with permission $right" );
+ }
+
+ public static function provideGetGroupsWithPermission() {
+ return [
+ [
+ [ 'unittesters', 'testwriters' ],
+ 'test'
+ ],
+ [
+ [ 'unittesters' ],
+ 'runtest'
+ ],
+ [
+ [ 'testwriters' ],
+ 'writetest'
+ ],
+ [
+ [ 'testwriters' ],
+ 'modifytest'
+ ],
+ ];
+ }
+
+ /**
+ * @covers \MediaWiki\Permissions\PermissionManager::userHasRight
+ */
+ public function testUserHasRight() {
+ $result = MediaWikiServices::getInstance()->getPermissionManager()->userHasRight(
+ $this->getTestUser( 'unittesters' )->getUser(),
+ 'test'
+ );
+ $this->assertTrue( $result );
+
+ $result = MediaWikiServices::getInstance()->getPermissionManager()->userHasRight(
+ $this->getTestUser( 'formertesters' )->getUser(),
+ 'runtest'
+ );
+ $this->assertFalse( $result );
+
+ $result = MediaWikiServices::getInstance()->getPermissionManager()->userHasRight(
+ $this->getTestUser( 'formertesters' )->getUser(),
+ ''
+ );
+ $this->assertTrue( $result );
+ }
+
+ /**
+ * @covers \MediaWiki\Permissions\PermissionManager::groupHasPermission
+ */
+ public function testGroupHasPermission() {
+ $result = MediaWikiServices::getInstance()->getPermissionManager()->groupHasPermission(
+ 'unittesters',
+ 'test'
+ );
+ $this->assertTrue( $result );
+
+ $result = MediaWikiServices::getInstance()->getPermissionManager()->groupHasPermission(
+ 'formertesters',
+ 'runtest'
+ );
+ $this->assertFalse( $result );
+ }
+
+ /**
+ * @covers \MediaWiki\Permissions\PermissionManager::isEveryoneAllowed
+ */
+ public function testIsEveryoneAllowed() {
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
+ ->isEveryoneAllowed( 'editmyoptions' );
+ $this->assertTrue( $result );
+
+ $result = MediaWikiServices::getInstance()->getPermissionManager()
+ ->isEveryoneAllowed( 'test' );
+ $this->assertFalse( $result );
+ }
+
+ /**
+ * @covers \MediaWiki\Permissions\PermissionManager::addTemporaryUserRights
+ * @covers \MediaWiki\Permissions\PermissionManager::revokeTemporaryUserRights
+ */
+ public function testTemporaryUserRights() {
+ $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+ $this->overrideUserPermissions( $this->user, [ 'read', 'edit' ] );
+ // sanity checks
+ $this->assertEquals( [ 'read', 'edit' ], $permissionManager->getUserPermissions( $this->user ) );
+ $this->assertFalse( $permissionManager->userHasRight( $this->user, 'move' ) );
+
+ $scope = $permissionManager->addTemporaryUserRights( $this->user, [ 'move', 'delete' ] );
+ $this->assertEquals( [ 'read', 'edit', 'move', 'delete' ],
+ $permissionManager->getUserPermissions( $this->user ) );
+ $this->assertTrue( $permissionManager->userHasRight( $this->user, 'move' ) );
+
+ $scope2 = $permissionManager->addTemporaryUserRights( $this->user, [ 'delete', 'upload' ] );
+ $this->assertEquals( [ 'read', 'edit', 'move', 'delete', 'upload' ],
+ $permissionManager->getUserPermissions( $this->user ) );
+
+ ScopedCallback::consume( $scope );
+ $this->assertEquals( [ 'read', 'edit', 'delete', 'upload' ],
+ $permissionManager->getUserPermissions( $this->user ) );
+ ScopedCallback::consume( $scope2 );
+ $this->assertEquals( [ 'read', 'edit' ],
+ $permissionManager->getUserPermissions( $this->user ) );
+ $this->assertFalse( $permissionManager->userHasRight( $this->user, 'move' ) );
+
+ ( function () use ( $permissionManager ) {
+ $scope = $permissionManager->addTemporaryUserRights( $this->user, 'move' );
+ $this->assertTrue( $permissionManager->userHasRight( $this->user, 'move' ) );
+ } )();
+ $this->assertFalse( $permissionManager->userHasRight( $this->user, 'move' ) );
+ }
+
}