r61562 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61561‎ | r61562 | r61563 >
Date:07:00, 27 January 2010
Author:mah
Status:resolved (Comments)
Tags:
Comment:
Parser tests now working under phpunit
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/tests/MediaWikiParserTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/MediaWikiParserTest.php
@@ -0,0 +1,219 @@
 2+<?php
 3+
 4+global $IP;
 5+define( "NO_COMMAND_LINE", 1 );
 6+require_once( "$IP/maintenance/parserTests.inc" );
 7+require_once( "ImageFunctions.php" );
 8+require_once( "ProxyTools.php" );
 9+require_once( "ObjectCache.php" );
 10+
 11+class PTShell extends ParserTest {
 12+
 13+ private $cb;
 14+
 15+ function setCallback( $cb ) {
 16+ $this->cb = $cb;
 17+ }
 18+
 19+ function showTesting( $desc ) {
 20+ }
 21+
 22+ function showRunFile( $path ) {
 23+ }
 24+
 25+ function showSuccess( $desc ) {
 26+ $this->cb->assertTrue( true, $desc );
 27+ echo "PASSED: $desc\n";
 28+ return true;
 29+ }
 30+
 31+ function showFailure( $desc, $expected, $got ) {
 32+ /* $this->cb->assertEquals( $expected, $got, $desc ); */
 33+ echo "FAILED: $desc\n";
 34+ echo "got: $got\n";
 35+ echo "expected: $expected\n";
 36+ }
 37+}
 38+
 39+class MediaWikiParserTest extends PHPUnit_Framework_TestCase {
 40+ private $parserTester;
 41+ private $db;
 42+ private $uploadDir;
 43+ private $keepUploads;
 44+
 45+ /**
 46+ * Remove the dummy uploads directory
 47+ */
 48+ private function teardownUploadDir( $dir ) {
 49+ if ( $this->keepUploads ) {
 50+ return;
 51+ }
 52+
 53+ // delete the files first, then the dirs.
 54+ self::deleteFiles(
 55+ array (
 56+ "$dir/3/3a/Foobar.jpg",
 57+ "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
 58+ "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
 59+ "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
 60+ "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
 61+
 62+ "$dir/0/09/Bad.jpg",
 63+ )
 64+ );
 65+
 66+ self::deleteDirs(
 67+ array (
 68+ "$dir/3/3a",
 69+ "$dir/3",
 70+ "$dir/thumb/6/65",
 71+ "$dir/thumb/6",
 72+ "$dir/thumb/3/3a/Foobar.jpg",
 73+ "$dir/thumb/3/3a",
 74+ "$dir/thumb/3",
 75+
 76+ "$dir/0/09/",
 77+ "$dir/0/",
 78+
 79+ "$dir/thumb",
 80+ "$dir",
 81+ )
 82+ );
 83+ }
 84+
 85+ /**
 86+ * Delete the specified files, if they exist.
 87+ * @param array $files full paths to files to delete.
 88+ */
 89+ private static function deleteFiles( $files ) {
 90+ foreach( $files as $file ) {
 91+ if( file_exists( $file ) ) {
 92+ unlink( $file );
 93+ }
 94+ }
 95+ }
 96+ /**
 97+ * Delete the specified directories, if they exist. Must be empty.
 98+ * @param array $dirs full paths to directories to delete.
 99+ */
 100+ private static function deleteDirs( $dirs ) {
 101+ foreach( $dirs as $dir ) {
 102+ if( is_dir( $dir ) ) {
 103+ rmdir( $dir );
 104+ }
 105+ }
 106+ }
 107+
 108+ /**
 109+ * Create a dummy uploads directory which will contain a couple
 110+ * of files in order to pass existence tests.
 111+ * @return string The directory
 112+ */
 113+ private function setupUploadDir() {
 114+ global $IP;
 115+ if ( $this->keepUploads ) {
 116+ $dir = wfTempDir() . '/mwParser-images';
 117+ if ( is_dir( $dir ) ) {
 118+ return $dir;
 119+ }
 120+ } else {
 121+ $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
 122+ }
 123+
 124+ wfDebug( "Creating upload directory $dir\n" );
 125+ if ( file_exists( $dir ) ) {
 126+ wfDebug( "Already exists!\n" );
 127+ return $dir;
 128+ }
 129+ wfMkdirParents( $dir . '/3/3a' );
 130+ copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
 131+
 132+ wfMkdirParents( $dir . '/0/09' );
 133+ copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
 134+ return $dir;
 135+ }
 136+
 137+ function setUp() {
 138+ global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
 139+ $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgMessageCache,
 140+ $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, $wgNamespaceAliases, $wgNamespaceProtection,
 141+ $wgLocalFileRepo, $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath,
 142+ $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
 143+
 144+ $wgScript = '/index.php';
 145+ $wgScriptPath = '/';
 146+ $wgArticlePath = '/wiki/$1';
 147+ $wgStyleSheetPath = '/skins';
 148+ $wgStylePath = '/skins';
 149+ $wgThumbnailScriptPath = false;
 150+ $this->uploadDir = $this->setupUploadDir();
 151+ $wgLocalFileRepo = array(
 152+ 'class' => 'LocalRepo',
 153+ 'name' => 'local',
 154+ 'directory' => $this->uploadDir,
 155+ 'url' => 'http://example.com/images',
 156+ 'hashLevels' => 2,
 157+ 'transformVia404' => false,
 158+ );
 159+ //$wgNamespacesWithSubpages = array( 0 => isset( $opts['subpage'] ) );
 160+ $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
 161+ $wgNamespaceAliases['Image'] = NS_FILE;
 162+ $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 163+
 164+
 165+ $wgEnableParserCache = false;
 166+ $wgDeferredUpdateList = array();
 167+ $wgMemc =& wfGetMainCache();
 168+ $messageMemc =& wfGetMessageCacheStorage();
 169+ $parserMemc =& wfGetParserCacheStorage();
 170+
 171+ $wgContLang = new StubContLang;
 172+ $wgUser = new StubUser;
 173+ $wgLang = new StubUserLang;
 174+ $wgOut = new StubObject( 'wgOut', 'OutputPage' );
 175+ $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
 176+ $wgRequest = new WebRequest;
 177+
 178+ $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
 179+ array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
 180+ if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
 181+
 182+ $this->parserTester = new PTShell();
 183+ $this->parserTester->setCallback( $this );
 184+
 185+ /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
 186+ /* $this->db['type'] = $wgDBtype; */
 187+ /* $this->db['server'] = $wgDBserver; */
 188+ /* $this->db['name'] = $wgDBname; */
 189+ /* $this->db['user'] = $wgDBuser; */
 190+ /* $this->db['password'] = $wgDBpassword; */
 191+ /* $this->db['port'] = $wgDBport; */
 192+ /* $this->db['mwschema'] = $wgDBmwschema; */
 193+ /* $this->db['ts2schema'] = $wgDBts2chema; */
 194+ }
 195+
 196+ function tearDown() {
 197+ $this->teardownUploadDir($this->uploadDir);
 198+ /* $db = wfGetDB( DB_MASTER ); */
 199+ /* $db->close(); */
 200+ /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
 201+
 202+ /* $wgDBtype = $this->db['type']; */
 203+ /* $wgDBserver = $this->db['server']; */
 204+ /* $wgDBname = $this->db['name']; */
 205+ /* $wgDBuser = $this->db['user']; */
 206+ /* $wgDBpassword = $this->db['password']; */
 207+ /* $wgDBport = $this->db['port']; */
 208+ /* $wgDBmwschema = $this->db['mwschema']; */
 209+ /* $wgDBts2chema = $this->db['ts2schema']; */
 210+
 211+ }
 212+
 213+
 214+ function testParser() {
 215+ global $IP;
 216+
 217+ $this->parserTester->runTestsFromFiles( array( "$IP/maintenance/parserTests.txt" ) );
 218+ }
 219+}
 220+
Property changes on: trunk/phase3/tests/MediaWikiParserTest.php
___________________________________________________________________
Name: svn:eol-syle
1221 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -213,6 +213,7 @@
214214 'SqlBagOStuff' => 'includes/BagOStuff.php',
215215 'SquidUpdate' => 'includes/SquidUpdate.php',
216216 'Status' => 'includes/Status.php',
 217+ 'StubContLang' => 'includes/StubObject.php',
217218 'StubUser' => 'includes/StubObject.php',
218219 'StubUserLang' => 'includes/StubObject.php',
219220 'StubObject' => 'includes/StubObject.php',

Comments

#Comment by Tim Starling (talk | contribs)   03:24, 24 June 2010

This is a register_globals arbitrary inclusion vulnerability. Please review Security for developers.

#Comment by Tim Starling (talk | contribs)   02:58, 25 June 2010

Fixed in r68544.

Status & tagging log