X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FMWNamespaceTest.php;h=5de5cc95da433e9d82e4d081d6b5d6e7690b2aec;hb=312c7f2c1a05795c40af44e2c40700d4ee2489b4;hp=da36ffda4016ae4bc74b72284895321dfc8f3393;hpb=5ec99f4b24f7ce2bd4028d62c88d6adf44bda3f9;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/MWNamespaceTest.php b/tests/phpunit/includes/MWNamespaceTest.php index da36ffda40..5de5cc95da 100644 --- a/tests/phpunit/includes/MWNamespaceTest.php +++ b/tests/phpunit/includes/MWNamespaceTest.php @@ -11,21 +11,22 @@ * */ class MWNamespaceTest extends MediaWikiTestCase { - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ protected function setUp() { - } + parent::setUp(); - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() { + $this->setMwGlobals( array( + 'wgContentNamespaces' => array( NS_MAIN ), + 'wgNamespacesWithSubpages' => array( + NS_TALK => true, + NS_USER => true, + NS_USER_TALK => true, + ), + 'wgCapitalLinks' => true, + 'wgCapitalLinkOverrides' => array(), + 'wgNonincludableNamespaces' => array(), + ) ); } - #### START OF TESTS ######################################################### /** @@ -268,77 +269,36 @@ class MWNamespaceTest extends MediaWikiTestCase { public function testIsContent() { // NS_MAIN is a content namespace per DefaultSettings.php // and per function definition. - $this->assertIsContent( NS_MAIN ); - - global $wgContentNamespaces; - $saved = $wgContentNamespaces; - - $wgContentNamespaces[] = NS_MAIN; $this->assertIsContent( NS_MAIN ); // Other namespaces which are not expected to be content - if ( isset( $wgContentNamespaces[NS_MEDIA] ) ) { - unset( $wgContentNamespaces[NS_MEDIA] ); - } - $this->assertIsNotContent( NS_MEDIA ); - if ( isset( $wgContentNamespaces[NS_SPECIAL] ) ) { - unset( $wgContentNamespaces[NS_SPECIAL] ); - } + $this->assertIsNotContent( NS_MEDIA ); $this->assertIsNotContent( NS_SPECIAL ); - - if ( isset( $wgContentNamespaces[NS_TALK] ) ) { - unset( $wgContentNamespaces[NS_TALK] ); - } $this->assertIsNotContent( NS_TALK ); - - if ( isset( $wgContentNamespaces[NS_USER] ) ) { - unset( $wgContentNamespaces[NS_USER] ); - } $this->assertIsNotContent( NS_USER ); - - if ( isset( $wgContentNamespaces[NS_CATEGORY] ) ) { - unset( $wgContentNamespaces[NS_CATEGORY] ); - } $this->assertIsNotContent( NS_CATEGORY ); - - if ( isset( $wgContentNamespaces[100] ) ) { - unset( $wgContentNamespaces[100] ); - } $this->assertIsNotContent( 100 ); - - $wgContentNamespaces = $saved; } /** * Similar to testIsContent() but alters the $wgContentNamespaces * global variable. */ - public function testIsContentWithAdditionsInWgContentNamespaces() { - // NS_MAIN is a content namespace per DefaultSettings.php - // and per function definition. - $this->assertIsContent( NS_MAIN ); + public function testIsContentAdvanced() { + global $wgContentNamespaces; - // Tests that user defined namespace #252 is not content: + // Test that user defined namespace #252 is not content $this->assertIsNotContent( 252 ); - # @todo FIXME: Is global saving really required for PHPUnit? // Bless namespace # 252 as a content namespace - global $wgContentNamespaces; - $savedGlobal = $wgContentNamespaces; $wgContentNamespaces[] = 252; + $this->assertIsContent( 252 ); // Makes sure NS_MAIN was not impacted $this->assertIsContent( NS_MAIN ); - - // Restore global - $wgContentNamespaces = $savedGlobal; - - // Verify namespaces after global restauration - $this->assertIsContent( NS_MAIN ); - $this->assertIsNotContent( 252 ); } public function testIsWatchable() { @@ -356,31 +316,21 @@ class MWNamespaceTest extends MediaWikiTestCase { } public function testHasSubpages() { + global $wgNamespacesWithSubpages; + // Special namespaces: $this->assertHasNotSubpages( NS_MEDIA ); $this->assertHasNotSubpages( NS_SPECIAL ); - // namespaces without subpages - # save up global - global $wgNamespacesWithSubpages; - $saved = null; - if( array_key_exists( NS_MAIN, $wgNamespacesWithSubpages ) ) { - $saved = $wgNamespacesWithSubpages[NS_MAIN]; - unset( $wgNamespacesWithSubpages[NS_MAIN] ); - } - + // Namespaces without subpages $this->assertHasNotSubpages( NS_MAIN ); $wgNamespacesWithSubpages[NS_MAIN] = true; $this->assertHasSubpages( NS_MAIN ); + $wgNamespacesWithSubpages[NS_MAIN] = false; $this->assertHasNotSubpages( NS_MAIN ); - # restore global - if( $saved !== null ) { - $wgNamespacesWithSubpages[NS_MAIN] = $saved; - } - // Some namespaces with subpages $this->assertHasSubpages( NS_TALK ); $this->assertHasSubpages( NS_USER ); @@ -390,22 +340,25 @@ class MWNamespaceTest extends MediaWikiTestCase { /** */ public function testGetContentNamespaces() { + global $wgContentNamespaces; + $this->assertEquals( array( NS_MAIN ), MWNamespace::getcontentNamespaces(), '$wgContentNamespaces is an array with only NS_MAIN by default' ); - global $wgContentNamespaces; - $saved = $wgContentNamespaces; # test !is_array( $wgcontentNamespaces ) $wgContentNamespaces = ''; $this->assertEquals( NS_MAIN, MWNamespace::getcontentNamespaces() ); + $wgContentNamespaces = false; $this->assertEquals( NS_MAIN, MWNamespace::getcontentNamespaces() ); + $wgContentNamespaces = null; $this->assertEquals( NS_MAIN, MWNamespace::getcontentNamespaces() ); + $wgContentNamespaces = 5; $this->assertEquals( NS_MAIN, MWNamespace::getcontentNamespaces() ); @@ -433,8 +386,36 @@ class MWNamespaceTest extends MediaWikiTestCase { array( NS_MAIN, NS_USER, NS_CATEGORY ), MWNamespace::getcontentNamespaces() ); + } + + /** + */ + public function testGetSubjectNamespaces() { + $subjectsNS = MWNamespace::getSubjectNamespaces(); + $this->assertContains( NS_MAIN, $subjectsNS, + "Talk namespaces should have NS_MAIN" ); + $this->assertNotContains( NS_TALK, $subjectsNS, + "Talk namespaces should have NS_TALK" ); + + $this->assertNotContains( NS_MEDIA, $subjectsNS, + "Talk namespaces should not have NS_MEDIA" ); + $this->assertNotContains( NS_SPECIAL, $subjectsNS, + "Talk namespaces should not have NS_SPECIAL" ); + } + + /** + */ + public function testGetTalkNamespaces() { + $talkNS = MWNamespace::getTalkNamespaces(); + $this->assertContains( NS_TALK, $talkNS, + "Subject namespaces should have NS_TALK" ); + $this->assertNotContains( NS_MAIN, $talkNS, + "Subject namespaces should not have NS_MAIN" ); - $wgContentNamespaces = $saved; + $this->assertNotContains( NS_MEDIA, $talkNS, + "Subject namespaces should not have NS_MEDIA" ); + $this->assertNotContains( NS_SPECIAL, $talkNS, + "Subject namespaces should not have NS_SPECIAL" ); } /** @@ -474,24 +455,20 @@ class MWNamespaceTest extends MediaWikiTestCase { */ public function testIsCapitalizedWithWgCapitalLinks() { global $wgCapitalLinks; - // Save the global to easily reset to MediaWiki default settings - $savedGlobal = $wgCapitalLinks; - $wgCapitalLinks = true; $this->assertIsCapitalized( NS_PROJECT ); $this->assertIsCapitalized( NS_PROJECT_TALK ); $wgCapitalLinks = false; + // hardcoded namespaces (see above function) are still capitalized: $this->assertIsCapitalized( NS_SPECIAL ); $this->assertIsCapitalized( NS_USER ); $this->assertIsCapitalized( NS_MEDIAWIKI ); + // setting is correctly applied $this->assertIsNotCapitalized( NS_PROJECT ); $this->assertIsNotCapitalized( NS_PROJECT_TALK ); - - // reset global state: - $wgCapitalLinks = $savedGlobal; } /** @@ -502,12 +479,11 @@ class MWNamespaceTest extends MediaWikiTestCase { */ public function testIsCapitalizedWithWgCapitalLinkOverrides() { global $wgCapitalLinkOverrides; - // Save the global to easily reset to MediaWiki default settings - $savedGlobal = $wgCapitalLinkOverrides; // Test default settings $this->assertIsCapitalized( NS_PROJECT ); $this->assertIsCapitalized( NS_PROJECT_TALK ); + // hardcoded namespaces (see above function) are capitalized: $this->assertIsCapitalized( NS_SPECIAL ); $this->assertIsCapitalized( NS_USER ); @@ -517,20 +493,19 @@ class MWNamespaceTest extends MediaWikiTestCase { $wgCapitalLinkOverrides[NS_SPECIAL] = false; $wgCapitalLinkOverrides[NS_USER] = false; $wgCapitalLinkOverrides[NS_MEDIAWIKI] = false; + $this->assertIsCapitalized( NS_SPECIAL ); $this->assertIsCapitalized( NS_USER ); $this->assertIsCapitalized( NS_MEDIAWIKI ); - $wgCapitalLinkOverrides = $savedGlobal; $wgCapitalLinkOverrides[NS_PROJECT] = false; $this->assertIsNotCapitalized( NS_PROJECT ); + $wgCapitalLinkOverrides[NS_PROJECT] = true ; $this->assertIsCapitalized( NS_PROJECT ); - unset( $wgCapitalLinkOverrides[NS_PROJECT] ); - $this->assertIsCapitalized( NS_PROJECT ); - // reset global state: - $wgCapitalLinkOverrides = $savedGlobal; + unset( $wgCapitalLinkOverrides[NS_PROJECT] ); + $this->assertIsCapitalized( NS_PROJECT ); } public function testHasGenderDistinction() { @@ -548,10 +523,10 @@ class MWNamespaceTest extends MediaWikiTestCase { public function testIsNonincludable() { global $wgNonincludableNamespaces; + $wgNonincludableNamespaces = array( NS_USER ); $this->assertTrue( MWNamespace::isNonincludable( NS_USER ) ); - $this->assertFalse( MWNamespace::isNonincludable( NS_TEMPLATE ) ); }