diff options
Diffstat (limited to 'tests/parser/parserTest.inc')
-rw-r--r-- | tests/parser/parserTest.inc | 124 |
1 files changed, 80 insertions, 44 deletions
diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index 0ce7c997..30e451b3 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -105,6 +105,9 @@ class ParserTest { $this->showOutput = isset( $options['show-output'] ); + if ( isset( $options['filter'] ) ) { + $options['regex'] = $options['filter']; + } if ( isset( $options['regex'] ) ) { if ( isset( $options['record'] ) ) { @@ -132,45 +135,65 @@ class ParserTest { } static function setUp() { - global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, + global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, $parserMemc, $wgThumbnailScriptPath, $wgScriptPath, - $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath; + $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath, $wgExtensionAssetsPath, + $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType; $wgScript = '/index.php'; $wgScriptPath = '/'; $wgArticlePath = '/wiki/$1'; $wgStyleSheetPath = '/skins'; $wgStylePath = '/skins'; + $wgExtensionAssetsPath = '/extensions'; $wgThumbnailScriptPath = false; $wgLocalFileRepo = array( - 'class' => 'LocalRepo', - 'name' => 'local', - 'directory' => wfTempDir() . '/test-repo', - 'url' => 'http://example.com/images', - 'deletedDir' => wfTempDir() . '/test-repo/delete', - 'hashLevels' => 2, + 'class' => 'LocalRepo', + 'name' => 'local', + 'url' => 'http://example.com/images', + 'hashLevels' => 2, 'transformVia404' => false, + 'backend' => new FSFileBackend( array( + 'name' => 'local-backend', + 'lockManager' => 'fsLockManager', + 'containerPaths' => array( + 'local-public' => wfTempDir() . '/test-repo/public', + 'local-thumb' => wfTempDir() . '/test-repo/thumb', + 'local-temp' => wfTempDir() . '/test-repo/temp', + 'local-deleted' => wfTempDir() . '/test-repo/deleted', + ) + ) ) ); $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface'; $wgNamespaceAliases['Image'] = NS_FILE; $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; + // XXX: tests won't run without this (for CACHE_DB) + if ( $wgMainCacheType === CACHE_DB ) { + $wgMainCacheType = CACHE_NONE; + } + if ( $wgMessageCacheType === CACHE_DB ) { + $wgMessageCacheType = CACHE_NONE; + } + if ( $wgParserCacheType === CACHE_DB ) { + $wgParserCacheType = CACHE_NONE; + } $wgEnableParserCache = false; - $wgDeferredUpdateList = array(); - $wgMemc = wfGetMainCache(); + DeferredUpdates::clearPendingUpdates(); + $wgMemc = wfGetMainCache(); // checks $wgMainCacheType $messageMemc = wfGetMessageCacheStorage(); $parserMemc = wfGetParserCacheStorage(); // $wgContLang = new StubContLang; $wgUser = new User; $context = new RequestContext; - $wgLang = $context->getLang(); + $wgLang = $context->getLanguage(); $wgOut = $context->getOutput(); $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) ); - $wgRequest = new WebRequest; + $wgRequest = $context->getRequest(); if ( $wgStyleDirectory === false ) { $wgStyleDirectory = "$IP/skins"; @@ -423,10 +446,10 @@ class ParserTest { } $opts = $this->parseOptions( $opts ); - $this->setupGlobals( $opts, $config ); + $context = $this->setupGlobals( $opts, $config ); - $user = new User(); - $options = ParserOptions::newFromUser( $user ); + $user = $context->getUser(); + $options = ParserOptions::newFromContext( $context ); if ( isset( $opts['title'] ) ) { $titleText = $opts['title']; @@ -452,8 +475,7 @@ class ParserTest { $replace = $opts['replace'][1]; $out = $parser->replaceSection( $input, $section, $replace ); } elseif ( isset( $opts['comment'] ) ) { - $linker = $user->getSkin(); - $out = $linker->formatComment( $input, $title, $local ); + $out = Linker::formatComment( $input, $title, $local ); } elseif ( isset( $opts['preload'] ) ) { $out = $parser->getpreloadText( $input, $title, $options ); } else { @@ -471,10 +493,9 @@ class ParserTest { if ( isset( $opts['ill'] ) ) { $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) ); } elseif ( isset( $opts['cat'] ) ) { - global $wgOut; - - $wgOut->addCategoryLinks( $output->getCategories() ); - $cats = $wgOut->getCategoryLinks(); + $outputPage = $context->getOutput(); + $outputPage->addCategoryLinks( $output->getCategories() ); + $cats = $outputPage->getCategoryLinks(); if ( isset( $cats['normal'] ) ) { $out = $this->tidy( implode( ' ', $cats['normal'] ) ); @@ -609,10 +630,19 @@ class ParserTest { 'wgLocalFileRepo' => array( 'class' => 'LocalRepo', 'name' => 'local', - 'directory' => $this->uploadDir, 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, + 'backend' => new FSFileBackend( array( + 'name' => 'local-backend', + 'lockManager' => 'fsLockManager', + 'containerPaths' => array( + 'local-public' => $this->uploadDir, + 'local-thumb' => $this->uploadDir . '/thumb', + 'local-temp' => $this->uploadDir . '/temp', + 'local-deleted' => $this->uploadDir . '/delete', + ) + ) ) ), 'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ), 'wgStylePath' => '/skins', @@ -650,6 +680,7 @@ class ParserTest { 'wgExternalLinkTarget' => false, 'wgAlwaysUseTidy' => false, 'wgHtml5' => true, + 'wgCleanupPresentationalAttributes' => true, 'wgWellFormedXml' => true, 'wgAllowMicrodataAttributes' => true, 'wgAdaptiveMessageCache' => true, @@ -681,7 +712,7 @@ class ParserTest { $GLOBALS['wgMemc'] = new EmptyBagOStuff; $context = new RequestContext(); - $GLOBALS['wgLang'] = $context->getLang(); + $GLOBALS['wgLang'] = $context->getLanguage(); $GLOBALS['wgOut'] = $context->getOutput(); $GLOBALS['wgUser'] = new User(); @@ -689,10 +720,11 @@ class ParserTest { global $wgHooks; $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup'; - $wgHooks['ParserTestParser'][] = 'ParserTestStaticParserHook::setup'; $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp'; MagicWord::clearCache(); + + return $context; } /** @@ -700,7 +732,7 @@ class ParserTest { * Some of these probably aren't necessary. */ private function listTables() { - $tables = array( 'user', 'user_properties', 'page', 'page_restrictions', + $tables = array( 'user', 'user_properties', 'user_former_groups', 'page', 'page_restrictions', 'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks', 'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks', 'site_stats', 'hitcounter', 'ipblocks', 'image', 'oldimage', @@ -709,8 +741,9 @@ class ParserTest { 'archive', 'user_groups', 'page_props', 'category', 'msg_resource', 'msg_resource_links' ); - if ( in_array( $this->db->getType(), array( 'mysql', 'sqlite', 'oracle' ) ) ) + if ( in_array( $this->db->getType(), array( 'mysql', 'sqlite', 'oracle' ) ) ) { array_push( $tables, 'searchindex' ); + } // Allow extensions to add to the list of tables to duplicate; // may be necessary if they hook into page save or other code @@ -753,17 +786,14 @@ class ParserTest { } $temporary = $this->useTemporaryTables || $dbType == 'postgres'; - $tables = $this->listTables(); $prefix = $dbType != 'oracle' ? 'parsertest_' : 'pt_'; $this->dbClone = new CloneDatabase( $this->db, $this->listTables(), $prefix ); $this->dbClone->useTemporaryTables( $temporary ); $this->dbClone->cloneTableStructure(); - if ( $dbType == 'oracle' ) - $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); - if ( $dbType == 'oracle' ) { + $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); # Insert 0 user to prevent FK violations # Anonymous user @@ -807,7 +837,6 @@ class ParserTest { 'iw_local' => 1 ), ) ); - # Update certain things in site_stats $this->db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) ); @@ -908,9 +937,9 @@ class ParserTest { return $dir; } - wfMkdirParents( $dir . '/3/3a' ); + wfMkdirParents( $dir . '/3/3a', null, __METHOD__ ); copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" ); - wfMkdirParents( $dir . '/0/09' ); + wfMkdirParents( $dir . '/0/09', null, __METHOD__ ); copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" ); return $dir; @@ -1077,7 +1106,9 @@ class ParserTest { $shellInfile = wfEscapeShellArg($infile); $shellOutfile = wfEscapeShellArg($outfile); - $diff = wfIsWindows() + global $wgDiff3; + // we assume that people with diff3 also have usual diff + $diff = ( wfIsWindows() && !$wgDiff3 ) ? `fc $shellInfile $shellOutfile` : `diff -au $shellInfile $shellOutfile`; unlink( $infile ); @@ -1130,30 +1161,35 @@ class ParserTest { * @param $name String: the title, including any prefix * @param $text String: the article text * @param $line Integer: the input line number, for reporting errors + * @param $ignoreDuplicate Boolean: whether to silently ignore duplicate pages */ - static public function addArticle( $name, $text, $line = 'unknown' ) { + static public function addArticle( $name, $text, $line = 'unknown', $ignoreDuplicate = '' ) { global $wgCapitalLinks; - $text = self::chomp($text); - $oldCapitalLinks = $wgCapitalLinks; $wgCapitalLinks = true; // We only need this from SetupGlobals() See r70917#c8637 + $text = self::chomp( $text ); $name = self::chomp( $name ); + $title = Title::newFromText( $name ); if ( is_null( $title ) ) { - throw new MWException( "invalid title ('$name' => '$title') at line $line\n" ); + throw new MWException( "invalid title '$name' at line $line\n" ); } - $aid = $title->getArticleID( Title::GAID_FOR_UPDATE ); + $page = WikiPage::factory( $title ); + $page->loadPageData( 'fromdbmaster' ); - if ( $aid != 0 ) { - throw new MWException( "duplicate article '$name' at line $line\n" ); + if ( $page->exists() ) { + if ( $ignoreDuplicate == 'ignoreduplicate' ) { + return; + } else { + throw new MWException( "duplicate article '$name' at line $line\n" ); + } } - $art = new Article( $title ); - $art->doEdit( $text, '', EDIT_NEW ); + $page->doEdit( $text, '', EDIT_NEW ); $wgCapitalLinks = $oldCapitalLinks; } @@ -1204,7 +1240,7 @@ class ParserTest { return true; } - /* + /** * Run the "tidy" command on text if the $wgUseTidy * global is true * |