2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2011-06-22 21:02:07 +00:00
|
|
|
class TitlePermissionTest extends MediaWikiLangTestCase {
|
2011-10-14 21:18:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @var string
|
2011-10-14 21:18:38 +00:00
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
protected $userName, $altUserName;
|
2011-10-14 21:18:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @var Title
|
2011-10-14 21:18:38 +00:00
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
protected $title;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
/**
|
|
|
|
|
* @var User
|
|
|
|
|
*/
|
|
|
|
|
protected $user, $anonUser, $userUser, $altUser;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$langObj = Language::factory( 'en' );
|
|
|
|
|
$localZone = 'UTC';
|
|
|
|
|
$localOffset = date( 'Z' ) / 60;
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgMemc' => new EmptyBagOStuff,
|
|
|
|
|
'wgContLang' => $langObj,
|
2012-11-05 10:10:42 +00:00
|
|
|
'wgLanguageCode' => 'en',
|
2012-10-08 10:56:20 +00:00
|
|
|
'wgLang' => $langObj,
|
|
|
|
|
'wgLocaltimezone' => $localZone,
|
|
|
|
|
'wgLocalTZoffset' => $localOffset,
|
|
|
|
|
'wgNamespaceProtection' => array(
|
|
|
|
|
NS_MEDIAWIKI => 'editinterface',
|
|
|
|
|
),
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
$this->userName = 'Useruser';
|
|
|
|
|
$this->altUserName = 'Altuseruser';
|
|
|
|
|
date_default_timezone_set( $localZone );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title = Title::makeTitle( NS_MAIN, "Main Page" );
|
|
|
|
|
if ( !isset( $this->userUser ) || !( $this->userUser instanceOf User ) ) {
|
|
|
|
|
$this->userUser = User::newFromName( $this->userName );
|
2011-04-23 19:28:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
if ( !$this->userUser->getID() ) {
|
|
|
|
|
$this->userUser = User::createNew( $this->userName, array(
|
2010-12-14 16:26:35 +00:00
|
|
|
"email" => "test@example.com",
|
|
|
|
|
"real_name" => "Test User" ) );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->userUser->load();
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
2011-04-23 19:28:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->altUser = User::newFromName( $this->altUserName );
|
|
|
|
|
if ( !$this->altUser->getID() ) {
|
|
|
|
|
$this->altUser = User::createNew( $this->altUserName, array(
|
2010-12-14 16:26:35 +00:00
|
|
|
"email" => "alttest@example.com",
|
|
|
|
|
"real_name" => "Test User Alt" ) );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->altUser->load();
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->anonUser = User::newFromId( 0 );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user = $this->userUser;
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-22 21:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
function setUserPerm( $perm ) {
|
2011-07-16 16:09:00 +00:00
|
|
|
// Setting member variables is evil!!!
|
|
|
|
|
|
2011-12-12 06:03:01 +00:00
|
|
|
if ( is_array( $perm ) ) {
|
|
|
|
|
$this->user->mRights = $perm;
|
|
|
|
|
} else {
|
|
|
|
|
$this->user->mRights = array( $perm );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setTitle( $ns, $title = "Main_Page" ) {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title = Title::makeTitle( $ns, $title );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setUser( $userName = null ) {
|
|
|
|
|
if ( $userName === 'anon' ) {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user = $this->anonUser;
|
2011-06-17 16:05:35 +00:00
|
|
|
} elseif ( $userName === null || $userName === $this->userName ) {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user = $this->userUser;
|
2010-12-14 16:26:35 +00:00
|
|
|
} else {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user = $this->altUser;
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testQuickPermissions() {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
$prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "createtalk" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array(), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "createpage" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( "nocreatetext" ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'nocreatetext' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "createpage" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "createtalk" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'nocreatetext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "createtalk" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "createpage" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_TALK );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "createpage" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "createtalk" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'create', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/subpage' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move-rootuserpages" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/subpage' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move-rootuserpages" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/subpage' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move-rootuserpages" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->userName . '/subpage' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move-rootuserpages" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_FILE, "img.png" );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_FILE, "img.png" );
|
|
|
|
|
$this->setUserPerm( "movefile" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenotallowed' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setTitle( NS_FILE, "img.png" );
|
|
|
|
|
$this->setUserPerm( "" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_FILE, "img.png" );
|
|
|
|
|
$this->setUserPerm( "movefile" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'movenologintext' ) ), $res );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "move" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( "" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setUserPerm( "move" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( "" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
|
|
|
|
|
array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
|
|
|
|
|
|
2012-10-12 11:09:08 +00:00
|
|
|
if ( $this->isWikitextNS( NS_MAIN ) ) {
|
|
|
|
|
//NOTE: some content models don't allow moving
|
|
|
|
|
//@todo: find a Wikitext namespace for testing
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setUserPerm( "move" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( ) );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( "" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
|
|
|
|
|
array( array( 'movenologintext' ) ) );
|
|
|
|
|
|
|
|
|
|
$this->setUser( $this->userName );
|
|
|
|
|
$this->setUserPerm( "" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( "move" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( ) );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setUserPerm( 'move' );
|
|
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
|
|
|
|
$this->assertEquals( array( ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( '' );
|
|
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
|
|
|
|
$this->assertEquals( array( array( 'movenotallowed' ) ), $res );
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_USER );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( array( "move", "move-rootuserpages" ) );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( "move" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$this->setUserPerm( array( "move", "move-rootuserpages" ) );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_USER, "User/subpage" );
|
|
|
|
|
$this->setUserPerm( array( "move", "move-rootuserpages" ) );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( "move" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ), $res );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
|
|
|
|
|
array( array( 'badaccess-group0' ) ),
|
|
|
|
|
array( ), true ),
|
|
|
|
|
'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
|
|
|
|
|
array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
|
|
|
|
|
array( array( 'protect-cantedit' ) ), false ),
|
|
|
|
|
'' => array( array( ), array( ), array( ), true ) );
|
2012-10-10 17:18:12 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
foreach ( array( "edit", "protect", "" ) as $action ) {
|
|
|
|
|
$this->setUserPerm( null );
|
|
|
|
|
$this->assertEquals( $check[$action][0],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, true ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
global $wgGroupPermissions;
|
|
|
|
|
$old = $wgGroupPermissions;
|
|
|
|
|
$wgGroupPermissions = array();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $check[$action][1],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, true ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgGroupPermissions = $old;
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( $action );
|
|
|
|
|
$this->assertEquals( $check[$action][2],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( $action, $this->user, true ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( $action );
|
|
|
|
|
$this->assertEquals( $check[$action][3],
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( $action, $this->user, true ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $check[$action][3],
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->quickUserCan( $action, $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
# count( User::getGroupsWithPermissions( $action ) ) < 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function runGroupPermissions( $action, $result, $result2 = null ) {
|
|
|
|
|
global $wgGroupPermissions;
|
|
|
|
|
|
|
|
|
|
if ( $result2 === null ) $result2 = $result;
|
|
|
|
|
|
|
|
|
|
$wgGroupPermissions['autoconfirmed']['move'] = false;
|
|
|
|
|
$wgGroupPermissions['user']['move'] = false;
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( $action, $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result, $res );
|
|
|
|
|
|
|
|
|
|
$wgGroupPermissions['autoconfirmed']['move'] = true;
|
|
|
|
|
$wgGroupPermissions['user']['move'] = false;
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( $action, $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result2, $res );
|
|
|
|
|
|
|
|
|
|
$wgGroupPermissions['autoconfirmed']['move'] = true;
|
|
|
|
|
$wgGroupPermissions['user']['move'] = true;
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( $action, $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result2, $res );
|
|
|
|
|
|
|
|
|
|
$wgGroupPermissions['autoconfirmed']['move'] = false;
|
|
|
|
|
$wgGroupPermissions['user']['move'] = true;
|
2010-12-31 22:08:13 +00:00
|
|
|
$res = $this->title->getUserPermissionsErrors( $action, $this->user );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $result2, $res );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testSpecialsAndNSPermissions() {
|
2012-10-08 10:56:20 +00:00
|
|
|
global $wgNamespaceProtection;
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_SPECIAL );
|
2011-04-23 19:28:35 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( 'bogus' );
|
|
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
|
|
|
|
$this->setUserPerm( '' );
|
|
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$wgNamespaceProtection[NS_USER] = array( 'bogus' );
|
|
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setTitle( NS_USER );
|
|
|
|
|
$this->setUserPerm( '' );
|
|
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIAWIKI );
|
|
|
|
|
$this->setUserPerm( 'bogus' );
|
|
|
|
|
$this->assertEquals( array( array( 'protectedinterface' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIAWIKI );
|
|
|
|
|
$this->setUserPerm( 'bogus' );
|
|
|
|
|
$this->assertEquals( array( array( 'protectedinterface' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$wgNamespaceProtection = null;
|
2012-10-08 10:56:20 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( 'bogus' );
|
|
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( true,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( '' );
|
|
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-03 18:09:30 +00:00
|
|
|
function testCssAndJavascriptPermissions() {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/test.js' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->runCSSandJSPermissions(
|
2011-06-05 18:42:50 +00:00
|
|
|
array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
|
|
|
|
|
array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
|
2010-12-14 16:26:35 +00:00
|
|
|
array( array( 'badaccess-group0' ) ) );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/test.css' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->runCSSandJSPermissions(
|
2011-06-05 18:42:50 +00:00
|
|
|
array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
|
2010-12-14 16:26:35 +00:00
|
|
|
array( array( 'badaccess-group0' ) ),
|
2011-06-05 18:42:50 +00:00
|
|
|
array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setTitle( NS_USER, $this->altUserName . '/tempo' );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->runCSSandJSPermissions(
|
|
|
|
|
array( array( 'badaccess-group0' ) ),
|
|
|
|
|
array( array( 'badaccess-group0' ) ),
|
|
|
|
|
array( array( 'badaccess-group0' ) ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function runCSSandJSPermissions( $result0, $result1, $result2 ) {
|
|
|
|
|
$this->setUserPerm( '' );
|
|
|
|
|
$this->assertEquals( $result0,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( 'editusercss' );
|
|
|
|
|
$this->assertEquals( $result1,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( 'edituserjs' );
|
|
|
|
|
$this->assertEquals( $result2,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( 'editusercssjs' );
|
|
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
|
|
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testPageRestrictions() {
|
2012-10-10 17:18:12 +00:00
|
|
|
global $wgContLang;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mRestrictionsLoaded = true;
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "edit" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( true,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->quickUserCan( 'edit', $this->user ) );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
|
2010-12-14 16:26:35 +00:00
|
|
|
"bogus" => array( 'bogus', "sysop", "protect", "" ) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ),
|
|
|
|
|
array( 'protectedpagetext', 'bogus' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
|
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ),
|
|
|
|
|
array( 'protectedpagetext', 'bogus' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
|
|
|
|
|
array( 'protectedpagetext', 'bogus' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( array( "edit", "editprotected" ) );
|
|
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ),
|
|
|
|
|
array( 'protectedpagetext', 'bogus' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
|
|
|
|
$this->title->mCascadeRestriction = true;
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->quickUserCan( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->quickUserCan( 'edit', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'badaccess-group0' ),
|
|
|
|
|
array( 'protectedpagetext', 'bogus' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ),
|
|
|
|
|
array( 'protectedpagetext', 'protect' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testCascadingSourcesRestrictions() {
|
|
|
|
|
$this->setTitle( NS_MAIN, "test page" );
|
|
|
|
|
$this->setUserPerm( array( "edit", "bogus" ) );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
|
|
|
|
|
$this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
|
|
|
|
|
array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( true,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'edit', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'edit', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testActionPermissions() {
|
|
|
|
|
$this->setUserPerm( array( "createpage" ) );
|
|
|
|
|
$this->setTitle( NS_MAIN, "test page" );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mTitleProtection['pt_create_perm'] = '';
|
|
|
|
|
$this->title->mTitleProtection['pt_user'] = $this->user->getID();
|
2011-10-14 21:18:38 +00:00
|
|
|
$this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mTitleProtection['pt_reason'] = 'test';
|
|
|
|
|
$this->title->mCascadeRestriction = false;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mTitleProtection['pt_create_perm'] = 'sysop';
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( array( 'createpage', 'protect' ) );
|
|
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( true,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( array( 'createpage' ) );
|
|
|
|
|
$this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'create', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIA, "test page" );
|
|
|
|
|
$this->setUserPerm( array( "move" ) );
|
|
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-12 11:09:08 +00:00
|
|
|
$this->setTitle( NS_HELP, "test page" );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( true,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mInterwiki = "no";
|
2011-08-30 11:39:43 +00:00
|
|
|
$this->assertEquals( array( array( 'immobile-source-page' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'move', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIA, "test page" );
|
|
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-12 11:09:08 +00:00
|
|
|
$this->setTitle( NS_HELP, "test page" );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( true,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->mInterwiki = "no";
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'immobile-target-page' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testUserBlock() {
|
2012-10-10 17:18:12 +00:00
|
|
|
global $wgEmailConfirmToEdit, $wgEmailAuthentication;
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgEmailConfirmToEdit = true;
|
|
|
|
|
$wgEmailAuthentication = true;
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( array( "createpage", "move" ) );
|
2012-10-12 11:09:08 +00:00
|
|
|
$this->setTitle( NS_HELP, "test page" );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
# $short
|
|
|
|
|
$this->assertEquals( array( array( 'confirmedittext' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgEmailConfirmToEdit = false;
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
# $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
|
|
|
|
|
$this->assertEquals( array( ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
global $wgLang;
|
|
|
|
|
$prev = time();
|
|
|
|
|
$now = time() + 120;
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user->mBlockedby = $this->user->getId();
|
2012-02-28 02:32:59 +00:00
|
|
|
$this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
|
2010-12-14 16:26:35 +00:00
|
|
|
'no reason given', $prev + 3600, 1, 0 );
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user->mBlock->mTimestamp = 0;
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'autoblockedtext',
|
|
|
|
|
'[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
|
2011-04-07 14:54:38 +00:00
|
|
|
'Useruser', null, 'infinite', '127.0.8.1',
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target',
|
|
|
|
|
$this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
|
2011-05-04 11:51:38 +00:00
|
|
|
// quickUserCan should ignore user blocks
|
2012-10-10 17:18:12 +00:00
|
|
|
$this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-07-02 11:11:01 +00:00
|
|
|
global $wgLocalTZoffset;
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgLocalTZoffset = -60;
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user->mBlockedby = $this->user->getName();
|
2012-02-28 02:32:59 +00:00
|
|
|
$this->user->mBlock = new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( array( array( 'blockedtext',
|
|
|
|
|
'[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
|
2011-04-07 14:54:38 +00:00
|
|
|
'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
|
2010-12-14 16:26:35 +00:00
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
# $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
|
|
|
|
|
# $user->blockedFor() == ''
|
|
|
|
|
# $user->mBlock->mExpiry == 'infinity'
|
|
|
|
|
}
|
|
|
|
|
}
|