Merge "API: Some raw message cleanup"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / NewParserTest.php
index c024555..ad84c20 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+use MediaWiki\MediaWikiServices;
+
 /**
  * Although marked as a stub, can work independently.
  *
@@ -94,7 +97,7 @@ class NewParserTest extends MediaWikiTestCase {
                $tmpGlobals['wgParserCacheType'] = CACHE_NONE;
                $tmpGlobals['wgCapitalLinks'] = true;
                $tmpGlobals['wgNoFollowLinks'] = true;
-               $tmpGlobals['wgNoFollowDomainExceptions'] = [];
+               $tmpGlobals['wgNoFollowDomainExceptions'] = [ 'no-nofollow.org' ];
                $tmpGlobals['wgExternalLinkTarget'] = false;
                $tmpGlobals['wgThumbnailScriptPath'] = false;
                $tmpGlobals['wgUseImageResize'] = true;
@@ -127,22 +130,6 @@ class NewParserTest extends MediaWikiTestCase {
                        $tmpGlobals['wgStyleDirectory'] = "$IP/skins";
                }
 
-               # Replace all media handlers with a mock. We do not need to generate
-               # actual thumbnails to do parser testing, we only care about receiving
-               # a ThumbnailImage properly initialized.
-               global $wgMediaHandlers;
-               foreach ( $wgMediaHandlers as $type => $handler ) {
-                       $tmpGlobals['wgMediaHandlers'][$type] = 'MockBitmapHandler';
-               }
-               // Vector images have to be handled slightly differently
-               $tmpGlobals['wgMediaHandlers']['image/svg+xml'] = 'MockSvgHandler';
-
-               // DjVu images have to be handled slightly differently
-               $tmpGlobals['wgMediaHandlers']['image/vnd.djvu'] = 'MockDjVuHandler';
-
-               // Ogg video/audio increasingly more differently
-               $tmpGlobals['wgMediaHandlers']['application/ogg'] = 'MockOggHandler';
-
                $tmpHooks = $wgHooks;
                $tmpHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
                $tmpHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
@@ -163,12 +150,8 @@ class NewParserTest extends MediaWikiTestCase {
                $this->djVuSupport = new DjVuSupport();
                // Tidy support
                $this->tidySupport = new TidySupport();
-               $tmpGlobals['wgTidyConfig'] = null;
+               $tmpGlobals['wgTidyConfig'] = $this->tidySupport->getConfig();
                $tmpGlobals['wgUseTidy'] = false;
-               $tmpGlobals['wgDebugTidy'] = false;
-               $tmpGlobals['wgTidyConf'] = $IP . '/includes/tidy/tidy.conf';
-               $tmpGlobals['wgTidyOpts'] = '';
-               $tmpGlobals['wgTidyInternal'] = $this->tidySupport->isInternal();
 
                $this->setMwGlobals( $tmpGlobals );
 
@@ -181,6 +164,13 @@ class NewParserTest extends MediaWikiTestCase {
                MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
                $wgContLang->resetNamespaces(); # reset namespace cache
                ParserTest::resetTitleServices();
+               MediaWikiServices::getInstance()->disableService( 'MediaHandlerFactory' );
+               MediaWikiServices::getInstance()->redefineService(
+                       'MediaHandlerFactory',
+                       function() {
+                               return new MockMediaHandlerFactory();
+                       }
+               );
        }
 
        protected function tearDown() {
@@ -200,6 +190,7 @@ class NewParserTest extends MediaWikiTestCase {
 
                // Restore message cache (temporary pages and $wgUseDatabaseMessages)
                MessageCache::destroyInstance();
+               MediaWikiServices::getInstance()->resetServiceForTesting( 'MediaHandlerFactory' );
 
                parent::tearDown();
 
@@ -324,7 +315,21 @@ class NewParserTest extends MediaWikiTestCase {
                        ], $this->db->timestamp( '20010115123500' ), $user );
                }
 
-               # A DjVu file
+               $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Audio.oga' ) );
+               if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
+                       $image->recordUpload2( '', 'An awesome hitsong ', 'Will it play', [
+                                       'size'        => 12345,
+                                       'width'       => 0,
+                                       'height'      => 0,
+                                       'bits'        => 0,
+                                       'media_type'  => MEDIATYPE_AUDIO,
+                                       'mime'        => 'application/ogg',
+                                       'metadata'    => serialize( [] ),
+                                       'sha1'        => Wikimedia\base_convert( '', 16, 36, 32 ),
+                                       'fileExists'  => true
+                       ], $this->db->timestamp( '20010115123500' ), $user );
+               }
+
                # A DjVu file
                $image = wfLocalFile( Title::makeTitle( NS_FILE, 'LoremIpsum.djvu' ) );
                if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
@@ -438,7 +443,8 @@ class NewParserTest extends MediaWikiTestCase {
                        'wgMathDirectory' => $uploadDir . '/math',
                        'wgDefaultLanguageVariant' => $variant,
                        'wgLinkHolderBatchSize' => $linkHolderBatchSize,
-                       'wgUseTidy' => isset( $opts['tidy'] ),
+                       'wgUseTidy' => false,
+                       'wgTidyConfig' => isset( $opts['tidy'] ) ? $this->tidySupport->getConfig() : null
                ];
 
                if ( $config ) {
@@ -706,6 +712,7 @@ class NewParserTest extends MediaWikiTestCase {
                if ( $this->regex != '' && !preg_match( '/' . $this->regex . '/', $desc ) ) {
                        $this->assertTrue( true ); // XXX: don't flood output with "test made no assertions"
                        // $this->markTestSkipped( 'Filtered out by the user' );
+                       $this->teardownGlobals();
                        return;
                }
 
@@ -713,6 +720,7 @@ class NewParserTest extends MediaWikiTestCase {
                        // parser tests frequently assume that the main namespace contains wikitext.
                        // @todo When setting up pages, force the content model. Only skip if
                        //        $wgtContentModelUseDB is false.
+                       $this->teardownGlobals();
                        $this->markTestSkipped( "Main namespace does not support wikitext,"
                                . "skipping parser test: $desc" );
                }
@@ -743,8 +751,10 @@ class NewParserTest extends MediaWikiTestCase {
                        global $wgTexvc;
 
                        if ( !isset( $wgTexvc ) ) {
+                               $this->teardownGlobals();
                                $this->markTestSkipped( "SKIPPED: \$wgTexvc is not set" );
                        } elseif ( !is_executable( $wgTexvc ) ) {
+                               $this->teardownGlobals();
                                $this->markTestSkipped( "SKIPPED: texvc binary does not exist"
                                        . " or is not executable.\n"
                                        . "Current configuration is:\n\$wgTexvc = '$wgTexvc'" );
@@ -753,12 +763,14 @@ class NewParserTest extends MediaWikiTestCase {
 
                if ( isset( $opts['djvu'] ) ) {
                        if ( !$this->djVuSupport->isEnabled() ) {
+                               $this->teardownGlobals();
                                $this->markTestSkipped( "SKIPPED: djvu binaries do not exist or are not executable.\n" );
                        }
                }
 
                if ( isset( $opts['tidy'] ) ) {
                        if ( !$this->tidySupport->isEnabled() ) {
+                               $this->teardownGlobals();
                                $this->markTestSkipped( "SKIPPED: tidy extension is not installed.\n" );
                        } else {
                                $options->setTidy( true );