2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2010-12-28 18:17:16 +00:00
|
|
|
class TitlePermissionTest extends MediaWikiTestCase {
|
2010-12-31 22:08:13 +00:00
|
|
|
protected $title;
|
|
|
|
|
protected $user;
|
|
|
|
|
protected $anonUser;
|
|
|
|
|
protected $userUser;
|
|
|
|
|
protected $altUser;
|
|
|
|
|
protected $userName;
|
|
|
|
|
protected $altUserName;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
function setUp() {
|
2011-01-26 15:42:04 +00:00
|
|
|
global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
if(!$wgMemc) {
|
2011-03-03 12:55:22 +00:00
|
|
|
$wgMemc = new EmptyBagOStuff;
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
$wgContLang = $wgLang = Language::factory( 'en' );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->userName = "Useruser";
|
|
|
|
|
$this->altUserName = "Altuseruser";
|
2010-12-14 16:26:35 +00:00
|
|
|
date_default_timezone_set( $wgLocaltimezone );
|
|
|
|
|
$wgLocalTZoffset = date( "Z" ) / 60;
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setUserPerm( $perm ) {
|
|
|
|
|
if ( is_array( $perm ) ) {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user->mRights = $perm;
|
2010-12-14 16:26:35 +00:00
|
|
|
} else {
|
2010-12-31 22:08:13 +00:00
|
|
|
$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;
|
|
|
|
|
} else if ( $userName === null || $userName === $this->userName ) {
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
global $wgUser;
|
2010-12-31 22:08:13 +00:00
|
|
|
$wgUser = $this->user;
|
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' ) ) );
|
|
|
|
|
|
|
|
|
|
$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' ) ) );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->setUserPerm( "" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
|
|
|
|
|
|
|
|
|
|
$this->setUserPerm( "move" );
|
|
|
|
|
$this->runGroupPermissions( 'move', array( ) );
|
|
|
|
|
|
|
|
|
|
$this->setUser( 'anon' );
|
|
|
|
|
$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->setUserPerm( '' );
|
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( 'movenotallowed' ) ), $res );
|
|
|
|
|
|
|
|
|
|
$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 ) );
|
|
|
|
|
global $wgUser;
|
2010-12-31 22:08:13 +00:00
|
|
|
$wgUser = $this->user;
|
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],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( $action, true ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( $check[$action][3],
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->quickUserCan( $action, false ) );
|
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 testPermissionHooks() { }
|
|
|
|
|
function testSpecialsAndNSPermissions() {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
global $wgUser, $wgContLang;
|
2010-12-31 22:08:13 +00:00
|
|
|
$wgUser = $this->user;
|
2010-12-14 16:26:35 +00:00
|
|
|
$prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
|
|
|
|
|
|
|
|
|
|
$this->setTitle( NS_SPECIAL );
|
2010-12-31 22:08:13 +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->assertEquals( array( array( 'badaccess-group0' ) ),
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->getUserPermissionsErrors( 'execute', $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
|
|
|
|
|
|
|
|
global $wgNamespaceProtection;
|
|
|
|
|
$wgNamespaceProtection[NS_USER] = array ( 'bogus' );
|
|
|
|
|
$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;
|
|
|
|
|
$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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'bogus' ) );
|
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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'bogus' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testCSSandJSPermissions() {
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->setUser( $this->userName );
|
2010-12-14 16:26:35 +00:00
|
|
|
global $wgUser;
|
2010-12-31 22:08:13 +00:00
|
|
|
$wgUser = $this->user;
|
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(
|
|
|
|
|
array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
|
|
|
|
|
array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
|
|
|
|
|
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(
|
|
|
|
|
array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
|
|
|
|
|
array( array( 'badaccess-group0' ) ),
|
|
|
|
|
array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
|
|
|
|
|
|
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() {
|
|
|
|
|
global $wgUser, $wgContLang;
|
|
|
|
|
|
|
|
|
|
$prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
|
|
|
|
|
|
2010-12-31 22:08:13 +00:00
|
|
|
$wgUser = $this->user;
|
2010-12-14 16:26:35 +00:00
|
|
|
$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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->quickUserCan( 'edit', false ) );
|
|
|
|
|
$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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->quickUserCan( 'bogus', false ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( false,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->quickUserCan( 'edit', false ) );
|
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() {
|
|
|
|
|
global $wgUser;
|
2010-12-31 22:08:13 +00:00
|
|
|
$wgUser = $this->user;
|
2010-12-14 16:26:35 +00:00
|
|
|
$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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'bogus' ) );
|
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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'edit' ) );
|
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() {
|
|
|
|
|
global $wgUser;
|
2010-12-31 22:08:13 +00:00
|
|
|
$wgUser = $this->user;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
$this->title->mTitleProtection['pt_expiry'] = Block::infinity();
|
|
|
|
|
$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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'create' ) );
|
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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'create' ) );
|
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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'create' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIA, "test page" );
|
|
|
|
|
$this->setUserPerm( array( "move" ) );
|
|
|
|
|
$this->assertEquals( false,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'move' ) );
|
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
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN, "test page" );
|
|
|
|
|
$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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'move' ) );
|
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-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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'move' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setTitle( NS_MEDIA, "test page" );
|
|
|
|
|
$this->assertEquals( false,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'move-target' ) );
|
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
|
|
|
|
|
|
|
|
$this->setTitle( NS_MAIN, "test page" );
|
|
|
|
|
$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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'move-target' ) );
|
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,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'move-target' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testUserBlock() {
|
|
|
|
|
global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
|
|
|
|
|
$wgEmailConfirmToEdit = true;
|
|
|
|
|
$wgEmailAuthentication = true;
|
2010-12-31 22:08:13 +00:00
|
|
|
$wgUser = $this->user;
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->setUserPerm( array( "createpage", "move" ) );
|
|
|
|
|
$this->setTitle( NS_MAIN, "test page" );
|
|
|
|
|
|
|
|
|
|
# $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;
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->assertEquals( true, $this->title->userCan( 'move-target' ) );
|
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();
|
|
|
|
|
$this->user->mBlock = new Block( '127.0.8.1', $this->user->getId(), $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
|
|
|
|
|
|
|
|
$this->assertEquals( false,
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->title->userCan( 'move-target', $this->user ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
global $wgLocalTZoffset;
|
|
|
|
|
$wgLocalTZoffset = -60;
|
2010-12-31 22:08:13 +00:00
|
|
|
$this->user->mBlockedby = $this->user->getName();
|
|
|
|
|
$this->user->mBlock = new Block( '127.0.8.1', 2, 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'
|
|
|
|
|
}
|
|
|
|
|
}
|