Merge "(bug 40257) action=info no longer shows subpages where disabled"
[lhc/web/wiklou.git] / tests / phpunit / includes / ExtraParserTest.php
index 130a1c4..903a6d2 100644 (file)
@@ -3,20 +3,26 @@
 /**
  * Parser-related tests that don't suit for parserTests.txt
  */
-class ExtraParserTest extends PHPUnit_Framework_TestCase {
+class ExtraParserTest extends MediaWikiTestCase {
 
        function setUp() {
                global $wgMemc;
                global $wgContLang;
                global $wgShowDBErrorBacktrace;
+               global $wgLanguageCode;
+               global $wgAlwaysUseTidy;
 
                $wgShowDBErrorBacktrace = true;
+               $wgLanguageCode = 'en';
                $wgContLang = new Language( 'en' );
-               $wgMemc = new FakeMemCachedClient;
+               $wgMemc = new EmptyBagOStuff;
+               $wgAlwaysUseTidy = false;
                
                $this->options = new ParserOptions;
                $this->options->setTemplateCallback( array( __CLASS__, 'statelessFetchTemplate' ) );
                $this->parser = new Parser;
+
+               MagicWord::clearCache();
        }
 
        // Bug 8689 - Long numeric lines kill the parser
@@ -44,7 +50,7 @@ class ExtraParserTest extends PHPUnit_Framework_TestCase {
                global $wgUser;
                $title = Title::newFromText( __FUNCTION__ );
                $outputText = $this->parser->preSaveTransform( "Test\r\n{{subst:Foo}}\n{{Bar}}", $title, $wgUser, $this->options );
-               
+
                $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText );
        }
        
@@ -59,20 +65,48 @@ class ExtraParserTest extends PHPUnit_Framework_TestCase {
         * cleanSig() makes all templates substs and removes tildes
         */
        function testCleanSig() {
+               global $wgCleanSignatures;
+               $oldCleanSignature = $wgCleanSignatures;
+               $wgCleanSignatures = true;
+
                $title = Title::newFromText( __FUNCTION__ );
                $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" );
+
+               $wgCleanSignatures = $oldCleanSignature;
                
                $this->assertEquals( "{{SUBST:Foo}} ", $outputText );
        }
-       
+
        /**
-        * cleanSigInSig() just removes tildes
+        * cleanSig() should do nothing if disabled
         */
-       function testCleanSigInSig() {
+       function testCleanSigDisabled() {
+               global $wgCleanSignatures;
+               $oldCleanSignature = $wgCleanSignatures;
+               $wgCleanSignatures = false;
+
                $title = Title::newFromText( __FUNCTION__ );
-               $outputText = $this->parser->cleanSigInSig( "{{Foo}} ~~~~" );
+               $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" );
+
+               $wgCleanSignatures = $oldCleanSignature;
                
-               $this->assertEquals( "{{Foo}} ", $outputText );
+               $this->assertEquals( "{{Foo}} ~~~~", $outputText );
+       }
+       
+       /**
+        * cleanSigInSig() just removes tildes
+        * @dataProvider provideStringsForCleanSigInSig
+        */
+       function testCleanSigInSig( $in, $out ) {
+               $this->assertEquals( Parser::cleanSigInSig( $in), $out );
+       }
+       
+       function provideStringsForCleanSigInSig() {
+               return array(
+                       array( "{{Foo}} ~~~~", "{{Foo}} " ),
+                       array( "~~~", "" ),
+                       array( "~~~~~", "" ),
+               );
        }
        
        function testGetSection() {
@@ -108,4 +142,28 @@ class ExtraParserTest extends PHPUnit_Framework_TestCase {
                        'finalTitle' => $title,
                        'deps' => $deps );
        }
+
+       /**
+        * @group Database
+        */
+       function testTrackingCategory() {
+               $title = Title::newFromText( __FUNCTION__ );
+               $catName =  wfMessage( 'broken-file-category' )->inContentLanguage()->text();
+               $cat = Title::makeTitleSafe( NS_CATEGORY, $catName );
+               $expected = array( $cat->getDBkey() );
+               $parserOutput = $this->parser->parse( "[[file:nonexistent]]" , $title, $this->options );
+               $result = $parserOutput->getCategoryLinks();
+               $this->assertEquals( $expected, $result );
+       }
+
+       /**
+        * @group Database
+        */
+       function testTrackingCategorySpecial() {
+               // Special pages shouldn't have tracking cats.
+               $title = SpecialPage::getTitleFor( 'Contributions' );
+               $parserOutput = $this->parser->parse( "[[file:nonexistent]]" , $title, $this->options );
+               $result = $parserOutput->getCategoryLinks();
+               $this->assertEmpty( $result );
+       }
  }