Use ParserOutput stateless transforms
[lhc/web/wiklou.git] / tests / parser / ParserTestRunner.php
index 0dab130..44a00a8 100644 (file)
@@ -384,7 +384,7 @@ class ParserTestRunner {
                // Changing wgExtraNamespaces invalidates caches in MWNamespace and
                // any live Language object, both on setup and teardown
                $reset = function () {
-                       MWNamespace::getCanonicalNamespaces( true );
+                       MWNamespace::clearCaches();
                        $GLOBALS['wgContLang']->resetNamespaces();
                };
                $setup[] = $reset;
@@ -518,6 +518,8 @@ class ParserTestRunner {
        /**
         * Ensure a given setup stage has been done, throw an exception if it has
         * not.
+        * @param string $funcName
+        * @param string|null $funcName2
         */
        protected function checkSetupDone( $funcName, $funcName2 = null ) {
                if ( !$this->setupDone[$funcName]
@@ -700,6 +702,8 @@ class ParserTestRunner {
        /**
         * Determine whether the current parser has the hooks registered in it
         * that are required by a file read by TestFileReader.
+        * @param array $requirements
+        * @return bool
         */
        public function meetsRequirements( $requirements ) {
                foreach ( $requirements as $requirement ) {
@@ -849,8 +853,9 @@ class ParserTestRunner {
                        $out = $parser->getPreloadText( $test['input'], $title, $options );
                } else {
                        $output = $parser->parse( $test['input'], $title, $options, true, true, 1337 );
-                       $output->setTOCEnabled( !isset( $opts['notoc'] ) );
-                       $out = $output->getText();
+                       $out = $output->getText( [
+                               'allowTOC' => !isset( $opts['notoc'] )
+                       ] );
                        if ( isset( $opts['tidy'] ) ) {
                                $out = preg_replace( '/\s+$/', '', $out );
                        }
@@ -1147,7 +1152,7 @@ class ParserTestRunner {
         */
        private function listTables() {
                $tables = [ 'user', 'user_properties', 'user_former_groups', 'page', 'page_restrictions',
-                       'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks',
+                       'protected_titles', 'revision', 'ip_changes', 'text', 'pagelinks', 'imagelinks',
                        'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks',
                        'site_stats', 'ipblocks', 'image', 'oldimage',
                        'recentchanges', 'watchlist', 'interwiki', 'logging', 'log_search',
@@ -1588,11 +1593,21 @@ class ParserTestRunner {
                        throw new MWException( "invalid title '$name' at $file:$line\n" );
                }
 
+               $newContent = ContentHandler::makeContent( $text, $title );
+
                $page = WikiPage::factory( $title );
                $page->loadPageData( 'fromdbmaster' );
 
                if ( $page->exists() ) {
-                       throw new MWException( "duplicate article '$name' at $file:$line\n" );
+                       $content = $page->getContent( Revision::RAW );
+                       // Only reject the title, if the content/content model is different.
+                       // This makes it easier to create Template:(( or Template:)) in different extensions
+                       if ( $newContent->equals( $content ) ) {
+                               return;
+                       }
+                       throw new MWException(
+                               "duplicate article '$name' with different content at $file:$line\n"
+                       );
                }
 
                // Use mock parser, to make debugging of actual parser tests simpler.
@@ -1600,12 +1615,15 @@ class ParserTestRunner {
                // get a reference to the mock object.
                MessageCache::singleton()->getParser();
                $restore = $this->executeSetupSnippets( [ 'wgParser' => new ParserTestMockParser ] );
-               $status = $page->doEditContent(
-                       ContentHandler::makeContent( $text, $title ),
-                       '',
-                       EDIT_NEW | EDIT_INTERNAL
-               );
-               $restore();
+               try {
+                       $status = $page->doEditContent(
+                               $newContent,
+                               '',
+                               EDIT_NEW | EDIT_INTERNAL
+                       );
+               } finally {
+                       $restore();
+               }
 
                if ( !$status->isOK() ) {
                        throw new MWException( $status->getWikiText( false, false, 'en' ) );