Fix use of non-existent variable Parser::$config
authorTim Starling <tstarling@wikimedia.org>
Thu, 25 Oct 2018 23:14:15 +0000 (16:14 -0700)
committerTim Starling <tstarling@wikimedia.org>
Thu, 25 Oct 2018 23:27:55 +0000 (16:27 -0700)
Fix bug from Ib4394f370cb561ccf195338a1c2e9e465dcb3dc3

Add test.

Bug: T208000
Change-Id: Ia81cca1b64afef2af3cb8dff19719a7f0de9d306

includes/parser/Parser.php
tests/phpunit/includes/parser/ParserMethodsTest.php

index db04077..3509200 100644 (file)
@@ -5925,7 +5925,7 @@ class Parser {
        }
 
        private function makeLegacyAnchor( $sectionName ) {
-               $fragmentMode = $this->config->get( 'FragmentMode' );
+               $fragmentMode = $this->siteConfig->get( 'FragmentMode' );
                if ( isset( $fragmentMode[1] ) && $fragmentMode[1] === 'legacy' ) {
                        // ForAttribute() and ForLink() are the same for legacy encoding
                        $id = Sanitizer::escapeIdForAttribute( $sectionName, Sanitizer::ID_FALLBACK );
index 291d75b..d702084 100644 (file)
@@ -370,6 +370,21 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
                }
        }
 
+       public static function provideGuessSectionNameFromWikiText() {
+               return [
+                       [ '1/2', 'html5', '#1/2' ],
+                       [ '1/2', 'legacy', '#1.2F2' ],
+               ];
+       }
+
+       /** @dataProvider provideGuessSectionNameFromWikiText */
+       public function testGuessSectionNameFromWikiText( $input, $mode, $expected ) {
+               $this->setMwGlobals( [ 'wgFragmentMode' => [ $mode ] ] );
+               global $wgParser;
+               $result = $wgParser->guessSectionNameFromWikiText( $input );
+               $this->assertEquals( $result, $expected );
+       }
+
        // @todo Add tests for cleanSig() / cleanSigInSig(), getSection(),
        // replaceSection(), getPreloadText()
 }