Create redirects to titles correctly in WikitextContentHandler
[lhc/web/wiklou.git] / tests / phpunit / includes / content / WikitextContentHandlerTest.php
index 45d8140..d213251 100644 (file)
@@ -60,6 +60,36 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
                );
        }
 
+       /**
+        * @dataProvider provideMakeRedirectContent
+        * @param Title|string $title Title object or string for Title::newFromText()
+        * @param string $expected Serialized form of the content object built
+        */
+       public function testMakeRedirectContent( $title, $expected ) {
+               global $wgContLang;
+               $wgContLang->resetNamespaces();
+
+               if ( is_string( $title ) ) {
+                       $title = Title::newFromText( $title );
+               }
+               $content = $this->handler->makeRedirectContent( $title );
+               $this->assertEquals( $expected, $content->serialize() );
+       }
+
+       public static function provideMakeRedirectContent() {
+               return array(
+                       array( 'Hello', '#REDIRECT [[Hello]]' ),
+                       array( 'Template:Hello', '#REDIRECT [[Template:Hello]]' ),
+                       array( 'Hello#section', '#REDIRECT [[Hello#section]]' ),
+                       array( 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ),
+                       array( 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ),
+                       array( 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ),
+                       array( Title::makeTitle( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ),
+                       array( Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ),
+                       array( Title::makeTitle( NS_MAIN, 'Bar', 'fragment', 'google' ), '#REDIRECT [[google:Bar#fragment]]' ),
+               );
+       }
+
        /**
         * @dataProvider dataIsSupportedFormat
         */