From 4ec94591008dc9815b76128621689f917364cf43 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 12 Oct 2012 13:09:08 +0200 Subject: [PATCH] [Bug 40716] Fix SearchEngineTest etc with non-wikitext content. Several core tests fail if there is non-wikitext content in the main namespace. This change fixes SearchEngineTest and TitlePermissionTest for this case. More fixes are to come. Change-Id: I6a19b568c5700bc8584689de8f33e4b0b6ffc277 --- tests/phpunit/MediaWikiTestCase.php | 18 ++++++ .../phpunit/includes/TitlePermissionTest.php | 59 ++++++++++--------- .../includes/search/SearchEngineTest.php | 13 +++- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index ff13702871..9c2fb69e06 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -666,4 +666,22 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } } + /** + * Returns true iff the given namespace defaults to Wikitext + * according to $wgNamespaceContentModels + * + * @param int $ns The namespace ID to check + * + * @return bool + * @since 1.21 + */ + protected function isWikitextNS( $ns ) { + global $wgNamespaceContentModels; + + if ( isset( $wgNamespaceContentModels[$ns] ) ) { + return $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT; + } + + return true; + } } diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 5df8fe1b1c..f7387e1684 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -236,30 +236,35 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $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' ) ) ); - - $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 ); + 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 ); + } $this->setTitle( NS_USER ); $this->setUser( $this->userName ); @@ -582,7 +587,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ), $this->title->getUserPermissionsErrors( 'move', $this->user ) ); - $this->setTitle( NS_MAIN, "test page" ); + $this->setTitle( NS_HELP, "test page" ); $this->assertEquals( array( ), $this->title->getUserPermissionsErrors( 'move', $this->user ) ); $this->assertEquals( true, @@ -600,7 +605,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ), $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); - $this->setTitle( NS_MAIN, "test page" ); + $this->setTitle( NS_HELP, "test page" ); $this->assertEquals( array( ), $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); $this->assertEquals( true, @@ -621,7 +626,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $wgUser = $this->user; $this->setUserPerm( array( "createpage", "move" ) ); - $this->setTitle( NS_MAIN, "test page" ); + $this->setTitle( NS_HELP, "test page" ); # $short $this->assertEquals( array( array( 'confirmedittext' ) ), diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index 879e41f268..395e1a04bf 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -40,6 +40,12 @@ class SearchEngineTest extends MediaWikiTestCase { if ( $this->pageExists( 'Not_Main_Page' ) ) { return; } + + if ( !$this->isWikitextNS( NS_MAIN ) ) { + //@todo: cover the case of non-wikitext content in the main namespace + return; + } + $this->insertPage( "Not_Main_Page", "This is not a main page", 0 ); $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 ); $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 ); @@ -60,6 +66,11 @@ class SearchEngineTest extends MediaWikiTestCase { } function fetchIds( $results ) { + if ( !$this->isWikitextNS( NS_MAIN ) ) { + $this->markTestIncomplete( __CLASS__ . " does no yet support non-wikitext content " + . "in the main namespace"); + } + $this->assertTrue( is_object( $results ) ); $matches = array(); @@ -84,7 +95,7 @@ class SearchEngineTest extends MediaWikiTestCase { * @param $n Integer: unused */ function insertPage( $pageName, $text, $ns ) { - $title = Title::newFromText( $pageName ); + $title = Title::newFromText( $pageName, $ns ); $user = User::newFromName( 'WikiSysop' ); $comment = 'Search Test'; -- 2.20.1