Merge "API: Warn when unsupported PHP array syntax is used"
[lhc/web/wiklou.git] / tests / phpunit / includes / TitlePermissionTest.php
index 9144d0c..ac80a9a 100644 (file)
@@ -2,6 +2,9 @@
 
 /**
  * @group Database
+ *
+ * @covers Title::getUserPermissionsErrors
+ * @covers Title::getUserPermissionsErrorsInternal
  */
 class TitlePermissionTest extends MediaWikiLangTestCase {
 
@@ -44,7 +47,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                date_default_timezone_set( $localZone );
 
                $this->title = Title::makeTitle( NS_MAIN, "Main Page" );
-               if ( !isset( $this->userUser ) || !( $this->userUser instanceOf User ) ) {
+               if ( !isset( $this->userUser ) || !( $this->userUser instanceof User ) ) {
                        $this->userUser = User::newFromName( $this->userName );
 
                        if ( !$this->userUser->getID() ) {
@@ -68,7 +71,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                }
        }
 
-       function setUserPerm( $perm ) {
+       protected function setUserPerm( $perm ) {
                // Setting member variables is evil!!!
 
                if ( is_array( $perm ) ) {
@@ -78,11 +81,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 ) {
@@ -92,7 +95,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 );
 
@@ -221,15 +228,21 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
 
                $this->setUserPerm( "" );
-               $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
+               $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->runGroupPermissions(
+                       'move',
+                       array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
+                       array( array( 'movenotallowedfile' ), array( 'movenologintext' ) )
+               );
 
                if ( $this->isWikitextNS( NS_MAIN ) ) {
                        //NOTE: some content models don't allow moving
@@ -286,13 +299,25 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $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' ) ),
+               $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 ) );
+                               array( array( 'protect-cantedit' ) ),
+                               false
+                       ),
+                       '' => array( array(), array(), array(), true )
+               );
 
                foreach ( array( "edit", "protect", "" ) as $action ) {
                        $this->setUserPerm( null );
@@ -320,7 +345,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                }
        }
 
-       function runGroupPermissions( $action, $result, $result2 = null ) {
+       protected function runGroupPermissions( $action, $result, $result2 = null ) {
                global $wgGroupPermissions;
 
                if ( $result2 === null ) {
@@ -348,7 +373,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 );
 
@@ -399,7 +428,11 @@ 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' );
@@ -448,7 +481,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                );
        }
 
-       function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
+       protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
                $this->setUserPerm( '' );
                $this->assertEquals( $result0,
                        $this->title->getUserPermissionsErrors( 'bogus',
@@ -485,7 +518,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 );
@@ -576,12 +613,17 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                                $this->user ) );
        }
 
-       function testCascadingSourcesRestrictions() {
+       public function testCascadingSourcesRestrictions() {
                $this->setTitle( NS_MAIN, "test page" );
                $this->setUserPerm( array( "edit", "bogus" ) );
 
-               $this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
-               $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
+               $this->title->mCascadeSources = array(
+                       Title::makeTitle( NS_MAIN, "Bogus" ),
+                       Title::makeTitle( NS_MAIN, "UnBogus" )
+               );
+               $this->title->mCascadingRestrictions = array(
+                       "bogus" => array( 'bogus', "sysop", "protect", "" )
+               );
 
                $this->assertEquals( false,
                        $this->title->userCan( 'bogus', $this->user ) );
@@ -596,7 +638,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                        $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'] = '';
@@ -667,7 +713,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                        $this->title->userCan( 'move-target', $this->user ) );
        }
 
-       function testUserBlock() {
+       public function testUserBlock() {
                global $wgEmailConfirmToEdit, $wgEmailAuthentication;
                $wgEmailConfirmToEdit = true;
                $wgEmailAuthentication = true;