jenkins-bot has submitted this change and it was merged.

Change subject: Remove unused exception in SpecialPage::getTitleFor and add 
tests
......................................................................


Remove unused exception in SpecialPage::getTitleFor and add tests

The way the existing code was, it seems the exception condition
was never hit, as one could enter a bogus special page title in
SpecialPage::getTitleFor and it returns a Title object anyway.

Some tests are also added for SpecialPage::getTitleFor(),
although more refactoring my be required to truly unit test this,
vs. indirectly testing other stuff via static methods.

Change-Id: I6e427d047a2f8e58677eb65b50866f767078c255
---
M includes/SpecialPage.php
A tests/phpunit/includes/SpecialPageTest.php
2 files changed, 61 insertions(+), 5 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php
index a6195fc..20571d7 100644
--- a/includes/SpecialPage.php
+++ b/includes/SpecialPage.php
@@ -259,11 +259,7 @@
         */
        public static function getTitleFor( $name, $subpage = false, $fragment 
= '' ) {
                $name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
-               if ( $name ) {
-                       return Title::makeTitle( NS_SPECIAL, $name, $fragment );
-               } else {
-                       throw new MWException( "Invalid special page name 
\"$name\"" );
-               }
+               return Title::makeTitle( NS_SPECIAL, $name, $fragment );
        }
 
        /**
diff --git a/tests/phpunit/includes/SpecialPageTest.php 
b/tests/phpunit/includes/SpecialPageTest.php
new file mode 100644
index 0000000..fb8f7ad
--- /dev/null
+++ b/tests/phpunit/includes/SpecialPageTest.php
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * @covers SpecialPage
+ *
+ * @group Database
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ */
+class SpecialPageTest extends MediaWikiTestCase {
+
+       public function setUp() {
+               parent::setUp();
+
+               $this->setMwGlobals( array(
+                       'wgContLang' => Language::factory( 'en' )
+               ) );
+       }
+
+       /**
+        * @dataProvider getTitleForProvider
+        */
+       public function testGetTitleFor( $expectedName, $name ) {
+               $title = SpecialPage::getTitleFor( $name );
+               $expected = Title::makeTitle( NS_SPECIAL, $expectedName );
+               $this->assertEquals( $expected, $title );
+       }
+
+       public function getTitleForProvider() {
+               return array(
+                       array( 'UserLogin', 'Userlogin' )
+               );
+       }
+
+       /**
+        * @expectedException PHPUnit_Framework_Error_Notice
+        */
+       public function testInvalidGetTitleFor() {
+               $title = SpecialPage::getTitleFor( 'cat' );
+               $expected = Title::makeTitle( NS_SPECIAL, 'Cat' );
+               $this->assertEquals( $expected, $title );
+       }
+
+       /**
+        * @expectedException PHPUnit_Framework_Error_Notice
+        * @dataProvider getTitleForWithWarningProvider
+        */
+       public function testGetTitleForWithWarning( $expected, $name ) {
+               $title = SpecialPage::getTitleFor( $name );
+               $this->assertEquals( $expected, $title );
+       }
+
+       public function getTitleForWithWarningProvider() {
+               return array(
+                       array( Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 
'UserLogin' )
+               );
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/95783
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6e427d047a2f8e58677eb65b50866f767078c255
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to