r79447 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79446‎ | r79447 | r79448 >
Date:22:16, 1 January 2011
Author:soxred93
Status:resolved (Comments)
Tags:
Comment:
Followup r79443: Add some form of organization to the test autoloader
Modified paths:
  • /trunk/phase3/tests/TestsAutoLoader.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
@@ -1,7 +1,5 @@
22 <?php
33
4 -require_once( dirname( __FILE__ ) . '/NewParserHelpers.php' );
5 -
64 /**
75 * @group Database
86 */
@@ -12,6 +10,8 @@
1311 public $runDisabled = false;
1412 public $regex = '';
1513 public $showProgress = true;
 14+ public $savedInitialGlobals = array();
 15+ public $savedWeirdGlobals = array();
1616 public $savedGlobals = array();
1717 public $hooks = array();
1818 public $functionHooks = array();
@@ -26,7 +26,7 @@
2727 //PHPUnit + MediaWikiTestCase functions
2828
2929 function setUp() {
30 - global $wgContLang;
 30+ global $wgContLang, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgNamespaceProtection, $wgNamespaceAliases;
3131 $wgContLang = Language::factory( 'en' );
3232
3333
@@ -41,22 +41,15 @@
4242
4343 $this->keepUploads = $this->getCliArg( 'keep-uploads' );
4444
45 -
46 -
47 - global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
48 - $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
49 - $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
50 - $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
51 - $wgThumbnailScriptPath, $wgScriptPath,
52 - $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
53 -
54 - $wgScript = '/index.php';
55 - $wgScriptPath = '/';
56 - $wgArticlePath = '/wiki/$1';
57 - $wgStyleSheetPath = '/skins';
58 - $wgStylePath = '/skins';
59 - $wgThumbnailScriptPath = false;
60 - $wgLocalFileRepo = array(
 45+ $tmpGlobals = array();
 46+
 47+ $tmpGlobals['wgScript'] = '/index.php';
 48+ $tmpGlobals['wgScriptPath'] = '/';
 49+ $tmpGlobals['wgArticlePath'] = '/wiki/$1';
 50+ $tmpGlobals['wgStyleSheetPath'] = '/skins';
 51+ $tmpGlobals['wgStylePath'] = '/skins';
 52+ $tmpGlobals['wgThumbnailScriptPath'] = false;
 53+ $tmpGlobals['wgLocalFileRepo'] = array(
6154 'class' => 'LocalRepo',
6255 'name' => 'local',
6356 'directory' => wfTempDir() . '/test-repo',
@@ -65,34 +58,59 @@
6659 'hashLevels' => 2,
6760 'transformVia404' => false,
6861 );
69 - $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
70 - $wgNamespaceAliases['Image'] = NS_FILE;
71 - $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 62+
 63+ var_dump(2);
7264
73 -
74 - $wgEnableParserCache = false;
75 - $wgDeferredUpdateList = array();
76 - $wgMemc = &wfGetMainCache();
 65+ $tmpGlobals['wgEnableParserCache'] = false;
 66+ $tmpGlobals['wgDeferredUpdateList'] = array();
 67+ $tmpGlobals['wgMemc'] = &wfGetMainCache();
7768 $messageMemc = &wfGetMessageCacheStorage();
78 - $parserMemc = &wfGetParserCacheStorage();
 69+ $tmpGlobals['parserMemc'] = &wfGetParserCacheStorage();
7970
80 - // $wgContLang = new StubContLang;
81 - $wgUser = new User;
82 - $wgLang = new StubUserLang;
83 - $wgOut = new StubObject( 'wgOut', 'OutputPage' );
84 - $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
85 - $wgRequest = new WebRequest;
 71+ // $tmpGlobals['wgContLang'] = new StubContLang;
 72+ $tmpGlobals['wgUser'] = new User;
 73+ $tmpGlobals['wgLang'] = new StubUserLang;
 74+ $tmpGlobals['wgOut'] = new StubObject( 'wgOut', 'OutputPage' );
 75+ $tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
 76+ $tmpGlobals['wgRequest'] = new WebRequest;
8677
87 - $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
 78+ $tmpGlobals['wgMessageCache'] = new StubObject( 'wgMessageCache', 'MessageCache',
8879 array( $messageMemc, $wgUseDatabaseMessages,
8980 $wgMsgCacheExpiry ) );
90 - if ( $wgStyleDirectory === false ) {
91 - $wgStyleDirectory = "$IP/skins";
 81+ if ( $GLOBALS['wgStyleDirectory'] === false ) {
 82+ $tmpGlobals['wgStyleDirectory'] = "$IP/skins";
9283 }
9384
 85+
 86+ foreach ( $tmpGlobals as $var => $val ) {
 87+ if ( array_key_exists( $var, $GLOBALS ) ) {
 88+ $this->savedInitialGlobals[$var] = $GLOBALS[$var];
 89+ }
 90+
 91+ $GLOBALS[$var] = $val;
 92+ }
 93+
 94+ $this->savedWeirdGlobals['mw_namespace_protection'] = $wgNamespaceProtection[NS_MEDIAWIKI];
 95+ $this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
 96+ $this->savedWeirdGlobals['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
 97+
 98+ $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
 99+ $wgNamespaceAliases['Image'] = NS_FILE;
 100+ $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 101+
94102 }
95103
96104 public function tearDown() {
 105+
 106+ foreach ( $this->savedInitialGlobals as $var => $val ) {
 107+ $GLOBALS[$var] = $val;
 108+ }
 109+
 110+ global $wgNamespaceProtection, $wgNamespaceAliases;
 111+
 112+ $wgNamespaceProtection[NS_MEDIAWIKI] = $this->savedWeirdGlobals['mw_namespace_protection'];
 113+ $wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias'];
 114+ $wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias'];
97115 }
98116
99117 function addDBData() {
Index: trunk/phase3/tests/TestsAutoLoader.php
@@ -4,10 +4,20 @@
55 $testFolder = dirname( __FILE__ );
66
77 $wgAutoloadClasses += array(
 8+
 9+ //PHPUnit
810 'MediaWikiTestCase' => "$testFolder/phpunit/MediaWikiTestCase.php",
911 'MediaWikiPHPUnitCommand' => "$testFolder/phpunit/MediaWikiPHPUnitCommand.php",
10 - 'ApiTestSetup' => "$testFolder/phpunit/includes/api/ApiSetup.php",
11 - 'RandomImageGenerator' => "$testFolder/phpunit/includes/api/RandomImageGenerator.php",
 12+
 13+ //API
 14+ 'ApiTestSetup' => "$testFolder/phpunit/includes/api/ApiSetup.php",
 15+ 'RandomImageGenerator' => "$testFolder/phpunit/includes/api/RandomImageGenerator.php",
 16+
 17+ //Parser
 18+ 'ParserTestFileIterator' => "$testFolder/phpunit/includes/parser/NewParserHelpers.php",
 19+
 20+
 21+ //Selenium
1222 'SeleniumTestConstants' => "$testFolder/selenium/SeleniumTestConstants.php",
1323 );
1424

Follow-up revisions

RevisionCommit summaryAuthorDate
r79449Fix r79447: Remove debugging codesoxred9322:19, 1 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79443Use an autoloader for the tests, following the ideas from r72858....platonides22:04, 1 January 2011

Comments

#Comment by X! (talk | contribs)   22:18, 1 January 2011

Well, I forgot to svn diff before I did this. Anyway, I added a second form of global setting and unsetting to the setUp().

Status & tagging log