From 3a12d1f822071f32e80081ea66c58e66e6a98749 Mon Sep 17 00:00:00 2001 From: Platonides Date: Wed, 11 Aug 2010 21:23:43 +0000 Subject: [PATCH] Force $wgContLang to English at the entry point. This avoids early Titles being localized. Remove setupGlobals() from addArticle() Make the upload dir global. Make the fake uploads a bit saner. --- maintenance/parserTests.inc | 90 +++++++++-------------- maintenance/tests/MediaWikiParserTest.php | 3 +- 2 files changed, 37 insertions(+), 56 deletions(-) diff --git a/maintenance/parserTests.inc b/maintenance/parserTests.inc index 54c42fee1f..f574429463 100644 --- a/maintenance/parserTests.inc +++ b/maintenance/parserTests.inc @@ -41,7 +41,7 @@ class ParserTest { /** * boolean $useTemporaryTables Use temporary tables for the temporary database */ - private $useTemporaryTables = true; + private $useTemporaryTables = false; /** * boolean $databaseSetupDone True if the database has been set up @@ -145,6 +145,7 @@ class ParserTest { * Draw input from a set of test files */ function fuzzTest( $filenames ) { + $GLOBALS['wgContLang'] = Language::factory( 'en' ); $dict = $this->getFuzzInput( $filenames ); $dictSize = strlen( $dict ); $logMaxLength = log( $this->maxFuzzTestLength ); @@ -265,6 +266,7 @@ class ParserTest { * @return Boolean: true if passed all tests, false if any tests failed. */ public function runTestsFromFiles( $filenames ) { + $GLOBALS['wgContLang'] = Language::factory( 'en' ); $this->recorder->start(); $this->setupDatabase(); $ok = true; @@ -486,9 +488,6 @@ class ParserTest { */ private function setupGlobals( $opts = '', $config = '' ) { global $wgDBtype; - if ( !isset( $this->uploadDir ) ) { - $this->uploadDir = $this->setupUploadDir(); - } # Find out values for some special options. $lang = @@ -711,52 +710,13 @@ class ParserTest { if ( $wgDBtype == 'oracle' ) { - # Insert 0 and 1 user_ids to prevent FK violations + # Insert 0 user to prevent FK violations # Anonymous user $db->insert( 'user', array( 'user_id' => 0, 'user_name' => 'Anonymous' ) ); - - # Hack-on-Hack: Insert a test user to be able to insert an image - $db->insert( 'user', array( - 'user_id' => 1, - 'user_name' => 'Tester' ) ); - } - - # Hack: Insert an image to work with - $db->insert( 'image', array( - 'img_name' => 'Foobar.jpg', - 'img_size' => 12345, - 'img_description' => 'Some lame file', - 'img_user' => 1, - 'img_user_text' => 'WikiSysop', - 'img_timestamp' => $db->timestamp( '20010115123500' ), - 'img_width' => 1941, - 'img_height' => 220, - 'img_bits' => 24, - 'img_media_type' => MEDIATYPE_BITMAP, - 'img_major_mime' => "image", - 'img_minor_mime' => "jpeg", - 'img_metadata' => serialize( array() ), - ) ); - - # This image will be blacklisted in [[MediaWiki:Bad image list]] - $db->insert( 'image', array( - 'img_name' => 'Bad.jpg', - 'img_size' => 12345, - 'img_description' => 'zomgnotcensored', - 'img_user' => 1, - 'img_user_text' => 'WikiSysop', - 'img_timestamp' => $db->timestamp( '20010115123500' ), - 'img_width' => 320, - 'img_height' => 240, - 'img_bits' => 24, - 'img_media_type' => MEDIATYPE_BITMAP, - 'img_major_mime' => "image", - 'img_minor_mime' => "jpeg", - 'img_metadata' => serialize( array() ), - ) ); + } # Update certain things in site_stats $db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) ); @@ -767,6 +727,31 @@ class ParserTest { # Make a new message cache global $wgMessageCache, $wgMemc; $wgMessageCache = new MessageCache( $wgMemc, true, 3600 ); + + $this->uploadDir = $this->setupUploadDir(); + $user = User::createNew( 'WikiSysop' ); + $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) ); + $image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array( + 'width' => 1941, + 'height' => 220, + 'bits' => 24, + 'media_type' => MEDIATYPE_BITMAP, + 'mime' => 'image/jpeg', + 'metadata' => serialize( array() ), + 'fileExists' => true + ), $db->timestamp( '20010115123500' ), $user ); + + # This image will be blacklisted in [[MediaWiki:Bad image list]] + $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) ); + $image->recordUpload2( '', 'zomgnotcensored', 'Borderline image', array( + 'width' => 320, + 'height' => 240, + 'bits' => 24, + 'media_type' => MEDIATYPE_BITMAP, + 'mime' => 'image/jpeg', + 'metadata' => serialize( array() ), + 'fileExists' => true + ), $db->timestamp( '20010115123500' ), $user ); } /** @@ -791,6 +776,8 @@ class ParserTest { if ( !$this->databaseSetupDone ) { return; } + $this->teardownUploadDir( $this->uploadDir ); + $this->changePrefix( $this->oldTablePrefix ); $this->databaseSetupDone = false; if ( $this->useTemporaryTables ) { @@ -825,14 +812,13 @@ class ParserTest { $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images"; } - wfDebug( "Creating upload directory $dir\n" ); + //wfDebug( "Creating upload directory $dir\n" ); if ( file_exists( $dir ) ) { wfDebug( "Already exists!\n" ); return $dir; } wfMkdirParents( $dir . '/3/3a' ); copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" ); - wfMkdirParents( $dir . '/0/09' ); copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" ); return $dir; @@ -848,10 +834,6 @@ class ParserTest { foreach ( $this->savedGlobals as $var => $val ) { $GLOBALS[$var] = $val; } - if ( isset( $this->uploadDir ) ) { - $this->teardownUploadDir( $this->uploadDir ); - unset( $this->uploadDir ); - } } /** @@ -1045,7 +1027,6 @@ class ParserTest { * @param $line Integer: the input line number, for reporting errors */ public function addArticle( $name, $text, $line ) { - $this->setupGlobals(); $title = Title::newFromText( $name ); if ( is_null( $title ) ) { wfDie( "invalid title at line $line\n" ); @@ -1058,8 +1039,6 @@ class ParserTest { $art = new Article( $title ); $art->insertNewArticle( $text, '', false, false ); - - $this->teardownGlobals(); } /** @@ -1728,8 +1707,9 @@ class TestFileIterator implements Iterator { $section = null; continue; } + global $wgUseTeX; if ( $this->parser && - preg_match( '/\\bmath\\b/i', $data['options'] ) && !$this->parser->savedGlobals['wgUseTeX'] ) { + preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) { # don't run math tests if $wgUseTeX is set to false in LocalSettings $data = array(); $section = null; diff --git a/maintenance/tests/MediaWikiParserTest.php b/maintenance/tests/MediaWikiParserTest.php index 0410a96918..d109655b40 100644 --- a/maintenance/tests/MediaWikiParserTest.php +++ b/maintenance/tests/MediaWikiParserTest.php @@ -17,7 +17,8 @@ class MediaWikiParserTestSuite extends PHPUnit_Framework_TestSuite { public function run( PHPUnit_Framework_TestResult $result = null, $filter = false, array $groups = array(), array $excludeGroups = array(), $processIsolation = false ) { - global $IP; + global $IP, $wgContLang; + $wgContLang = Language::factory( 'en' ); $this->backend->setupDatabase(); $iter = new TestFileIterator( "$IP/maintenance/parserTests.txt" ); -- 2.20.1