summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/TitlePermissionTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/TitlePermissionTest.php')
-rw-r--r--tests/phpunit/includes/TitlePermissionTest.php142
1 files changed, 111 insertions, 31 deletions
diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php
index e2c079a7..f15c1772 100644
--- a/tests/phpunit/includes/TitlePermissionTest.php
+++ b/tests/phpunit/includes/TitlePermissionTest.php
@@ -2,6 +2,7 @@
/**
* @group Database
+ * @todo covers tags
*/
class TitlePermissionTest extends MediaWikiLangTestCase {
@@ -66,10 +67,9 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->user = $this->userUser;
}
-
}
- function setUserPerm( $perm ) {
+ protected function setUserPerm( $perm ) {
// Setting member variables is evil!!!
if ( is_array( $perm ) ) {
@@ -79,11 +79,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
}
}
- function setTitle( $ns, $title = "Main_Page" ) {
+ protected function setTitle( $ns, $title = "Main_Page" ) {
$this->title = Title::makeTitle( $ns, $title );
}
- function setUser( $userName = null ) {
+ protected function setUser( $userName = null ) {
if ( $userName === 'anon' ) {
$this->user = $this->anonUser;
} elseif ( $userName === null || $userName === $this->userName ) {
@@ -93,7 +93,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
}
}
- function testQuickPermissions() {
+ /**
+ * @todo This test method should be split up into separate test methods and
+ * data providers
+ */
+ public function testQuickPermissions() {
global $wgContLang;
$prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
@@ -234,7 +238,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
if ( $this->isWikitextNS( NS_MAIN ) ) {
//NOTE: some content models don't allow moving
- //@todo: find a Wikitext namespace for testing
+ // @todo find a Wikitext namespace for testing
$this->setTitle( NS_MAIN );
$this->setUser( 'anon' );
@@ -317,12 +321,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->title->userCan( $action, $this->user, true ) );
$this->assertEquals( $check[$action][3],
$this->title->quickUserCan( $action, $this->user ) );
-
# count( User::getGroupsWithPermissions( $action ) ) < 1
}
}
- function runGroupPermissions( $action, $result, $result2 = null ) {
+ protected function runGroupPermissions( $action, $result, $result2 = null ) {
global $wgGroupPermissions;
if ( $result2 === null ) {
@@ -350,7 +353,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->assertEquals( $result2, $res );
}
- function testSpecialsAndNSPermissions() {
+ /**
+ * @todo This test method should be split up into separate test methods and
+ * data providers
+ */
+ public function testSpecialsAndNSPermissions() {
global $wgNamespaceProtection;
$this->setUser( $this->userName );
@@ -401,44 +408,85 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->title->userCan( 'bogus', $this->user ) );
}
- function testCssAndJavascriptPermissions() {
+ /**
+ * @todo This test method should be split up into separate test methods and
+ * data providers
+ */
+ public function testCssAndJavascriptPermissions() {
$this->setUser( $this->userName );
+ $this->setTitle( NS_USER, $this->userName . '/test.js' );
+ $this->runCSSandJSPermissions(
+ array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
+ array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
+ array( array( 'badaccess-group0' ) ),
+ array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
+ array( array( 'badaccess-group0' ) )
+ );
+
+ $this->setTitle( NS_USER, $this->userName . '/test.css' );
+ $this->runCSSandJSPermissions(
+ array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ),
+ array( array( 'badaccess-group0' ) ),
+ array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ),
+ array( array( 'badaccess-group0' ) ),
+ array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) )
+ );
+
$this->setTitle( NS_USER, $this->altUserName . '/test.js' );
$this->runCSSandJSPermissions(
array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
- array( array( 'badaccess-group0' ) ) );
+ array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
+ array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
+ array( array( 'badaccess-group0' ) )
+ );
$this->setTitle( NS_USER, $this->altUserName . '/test.css' );
$this->runCSSandJSPermissions(
array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
+ array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
+ array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
array( array( 'badaccess-group0' ) ),
- array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
+ array( array( 'badaccess-group0' ), array( 'customcssprotected' ) )
+ );
$this->setTitle( NS_USER, $this->altUserName . '/tempo' );
$this->runCSSandJSPermissions(
array( array( 'badaccess-group0' ) ),
array( array( 'badaccess-group0' ) ),
- array( array( 'badaccess-group0' ) ) );
+ array( array( 'badaccess-group0' ) ),
+ array( array( 'badaccess-group0' ) ),
+ array( array( 'badaccess-group0' ) )
+ );
}
- function runCSSandJSPermissions( $result0, $result1, $result2 ) {
+ protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
$this->setUserPerm( '' );
$this->assertEquals( $result0,
$this->title->getUserPermissionsErrors( 'bogus',
$this->user ) );
- $this->setUserPerm( 'editusercss' );
+ $this->setUserPerm( 'editmyusercss' );
$this->assertEquals( $result1,
$this->title->getUserPermissionsErrors( 'bogus',
$this->user ) );
- $this->setUserPerm( 'edituserjs' );
+ $this->setUserPerm( 'editmyuserjs' );
$this->assertEquals( $result2,
$this->title->getUserPermissionsErrors( 'bogus',
$this->user ) );
+ $this->setUserPerm( 'editusercss' );
+ $this->assertEquals( $result3,
+ $this->title->getUserPermissionsErrors( 'bogus',
+ $this->user ) );
+
+ $this->setUserPerm( 'edituserjs' );
+ $this->assertEquals( $result4,
+ $this->title->getUserPermissionsErrors( 'bogus',
+ $this->user ) );
+
$this->setUserPerm( 'editusercssjs' );
$this->assertEquals( array( array( 'badaccess-group0' ) ),
$this->title->getUserPermissionsErrors( 'bogus',
@@ -450,7 +498,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->user ) );
}
- function testPageRestrictions() {
+ /**
+ * @todo This test method should be split up into separate test methods and
+ * data providers
+ */
+ public function testPageRestrictions() {
global $wgContLang;
$prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
@@ -471,39 +523,59 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->assertEquals( array( array( 'badaccess-group0' ),
array( 'protectedpagetext', 'bogus' ),
- array( 'protectedpagetext', 'protect' ),
+ array( 'protectedpagetext', 'editprotected' ),
array( 'protectedpagetext', 'protect' ) ),
$this->title->getUserPermissionsErrors( 'bogus',
$this->user ) );
$this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
- array( 'protectedpagetext', 'protect' ),
+ array( 'protectedpagetext', 'editprotected' ),
array( 'protectedpagetext', 'protect' ) ),
$this->title->getUserPermissionsErrors( 'edit',
$this->user ) );
$this->setUserPerm( "" );
$this->assertEquals( array( array( 'badaccess-group0' ),
array( 'protectedpagetext', 'bogus' ),
- array( 'protectedpagetext', 'protect' ),
+ array( 'protectedpagetext', 'editprotected' ),
array( 'protectedpagetext', 'protect' ) ),
$this->title->getUserPermissionsErrors( 'bogus',
$this->user ) );
$this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
array( 'protectedpagetext', 'bogus' ),
- array( 'protectedpagetext', 'protect' ),
+ array( 'protectedpagetext', 'editprotected' ),
array( 'protectedpagetext', 'protect' ) ),
$this->title->getUserPermissionsErrors( 'edit',
$this->user ) );
$this->setUserPerm( array( "edit", "editprotected" ) );
$this->assertEquals( array( array( 'badaccess-group0' ),
array( 'protectedpagetext', 'bogus' ),
- array( 'protectedpagetext', 'protect' ),
array( 'protectedpagetext', 'protect' ) ),
$this->title->getUserPermissionsErrors( 'bogus',
$this->user ) );
- $this->assertEquals( array(),
+ $this->assertEquals( array(
+ array( 'protectedpagetext', 'bogus' ),
+ array( 'protectedpagetext', 'protect' ) ),
$this->title->getUserPermissionsErrors( 'edit',
$this->user ) );
+
$this->title->mCascadeRestriction = true;
+ $this->setUserPerm( "edit" );
+ $this->assertEquals( false,
+ $this->title->quickUserCan( 'bogus', $this->user ) );
+ $this->assertEquals( false,
+ $this->title->quickUserCan( 'edit', $this->user ) );
+ $this->assertEquals( array( array( 'badaccess-group0' ),
+ array( 'protectedpagetext', 'bogus' ),
+ array( 'protectedpagetext', 'editprotected' ),
+ array( 'protectedpagetext', 'protect' ) ),
+ $this->title->getUserPermissionsErrors( 'bogus',
+ $this->user ) );
+ $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
+ array( 'protectedpagetext', 'editprotected' ),
+ array( 'protectedpagetext', 'protect' ) ),
+ $this->title->getUserPermissionsErrors( 'edit',
+ $this->user ) );
+
+ $this->setUserPerm( array( "edit", "editprotected" ) );
$this->assertEquals( false,
$this->title->quickUserCan( 'bogus', $this->user ) );
$this->assertEquals( false,
@@ -521,7 +593,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->user ) );
}
- function testCascadingSourcesRestrictions() {
+ public function testCascadingSourcesRestrictions() {
$this->setTitle( NS_MAIN, "test page" );
$this->setUserPerm( array( "edit", "bogus" ) );
@@ -531,6 +603,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->assertEquals( false,
$this->title->userCan( 'bogus', $this->user ) );
$this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
+ array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
@@ -538,10 +611,13 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->title->userCan( 'edit', $this->user ) );
$this->assertEquals( array(),
$this->title->getUserPermissionsErrors( 'edit', $this->user ) );
-
}
- function testActionPermissions() {
+ /**
+ * @todo This test method should be split up into separate test methods and
+ * data providers
+ */
+ public function testActionPermissions() {
$this->setUserPerm( array( "createpage" ) );
$this->setTitle( NS_MAIN, "test page" );
$this->title->mTitleProtection['pt_create_perm'] = '';
@@ -557,12 +633,17 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->title->mTitleProtection['pt_create_perm'] = 'sysop';
$this->setUserPerm( array( 'createpage', 'protect' ) );
+ $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
+ $this->title->getUserPermissionsErrors( 'create', $this->user ) );
+ $this->assertEquals( false,
+ $this->title->userCan( 'create', $this->user ) );
+
+ $this->setUserPerm( array( 'createpage', 'editprotected' ) );
$this->assertEquals( array(),
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
$this->assertEquals( true,
$this->title->userCan( 'create', $this->user ) );
-
$this->setUserPerm( array( 'createpage' ) );
$this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
$this->title->getUserPermissionsErrors( 'create', $this->user ) );
@@ -605,10 +686,9 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
$this->assertEquals( false,
$this->title->userCan( 'move-target', $this->user ) );
-
}
- function testUserBlock() {
+ public function testUserBlock() {
global $wgEmailConfirmToEdit, $wgEmailAuthentication;
$wgEmailConfirmToEdit = true;
$wgEmailAuthentication = true;
@@ -648,13 +728,13 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
global $wgLocalTZoffset;
$wgLocalTZoffset = -60;
$this->user->mBlockedby = $this->user->getName();
- $this->user->mBlock = new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
+ $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
+ 'no reason given', $now, 0, 10 );
$this->assertEquals( array( array( 'blockedtext',
'[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
$wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
-
# $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
# $user->blockedFor() == ''
# $user->mBlock->mExpiry == 'infinity'