Index: trunk/phase3/maintenance/parserTests.inc |
— | — | @@ -24,17 +24,6 @@ |
25 | 25 | * @ingroup Maintenance |
26 | 26 | */ |
27 | 27 | |
28 | | -/** */ |
29 | | -$options = array( 'quick', 'color', 'quiet', 'help', 'show-output', 'record', 'run-disabled' ); |
30 | | -$optionsWithArgs = array( 'regex', 'seed', 'setversion' ); |
31 | | - |
32 | | -if ( !defined( "NO_COMMAND_LINE" ) ) { |
33 | | - require_once( dirname( __FILE__ ) . '/commandLine.inc' ); |
34 | | -} |
35 | | -require_once( "$IP/maintenance/parserTestsParserHook.php" ); |
36 | | -require_once( "$IP/maintenance/parserTestsStaticParserHook.php" ); |
37 | | -require_once( "$IP/maintenance/parserTestsParserTime.php" ); |
38 | | - |
39 | 28 | /** |
40 | 29 | * @ingroup Maintenance |
41 | 30 | */ |
— | — | @@ -114,17 +103,7 @@ |
115 | 104 | $this->regex = ''; |
116 | 105 | } |
117 | 106 | |
118 | | - if ( isset( $options['record'] ) ) { |
119 | | - $this->recorder = new DbTestRecorder( $this ); |
120 | | - } elseif ( isset( $options['compare'] ) ) { |
121 | | - $this->recorder = new DbTestPreviewer( $this ); |
122 | | - } elseif ( isset( $options['upload'] ) ) { |
123 | | - $this->recorder = new RemoteTestRecorder( $this ); |
124 | | - } elseif ( class_exists( 'PHPUnitTestRecorder' ) ) { |
125 | | - $this->recorder = new PHPUnitTestRecorder( $this ); |
126 | | - } else { |
127 | | - $this->recorder = new TestRecorder( $this ); |
128 | | - } |
| 107 | + $this->setupRecorder(); |
129 | 108 | $this->keepUploads = isset( $options['keep-uploads'] ); |
130 | 109 | |
131 | 110 | if ( isset( $options['seed'] ) ) { |
— | — | @@ -137,6 +116,18 @@ |
138 | 117 | $this->functionHooks = array(); |
139 | 118 | } |
140 | 119 | |
| 120 | + public function setupRecorder() { |
| 121 | + if ( isset( $options['record'] ) ) { |
| 122 | + $this->recorder = new DbTestRecorder( $this ); |
| 123 | + } elseif ( isset( $options['compare'] ) ) { |
| 124 | + $this->recorder = new DbTestPreviewer( $this ); |
| 125 | + } elseif ( isset( $options['upload'] ) ) { |
| 126 | + $this->recorder = new RemoteTestRecorder( $this ); |
| 127 | + } else { |
| 128 | + $this->recorder = new TestRecorder( $this ); |
| 129 | + } |
| 130 | + } |
| 131 | + |
141 | 132 | /** |
142 | 133 | * Remove last character if it is a newline |
143 | 134 | */ |
— | — | @@ -589,6 +580,11 @@ |
590 | 581 | $GLOBALS['wgMemc'] = new FakeMemCachedClient; |
591 | 582 | $GLOBALS['wgOut'] = new OutputPage; |
592 | 583 | |
| 584 | + global $wgHooks; |
| 585 | + $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup'; |
| 586 | + $wgHooks['ParserTestParser'][] = 'ParserTestStaticParserHook::setup'; |
| 587 | + $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp'; |
| 588 | + |
593 | 589 | MagicWord::clearCache(); |
594 | 590 | |
595 | 591 | global $wgUser; |
— | — | @@ -626,7 +622,7 @@ |
627 | 623 | * Currently this will only be done once per run, and any changes to |
628 | 624 | * the db will be visible to later tests in the run. |
629 | 625 | */ |
630 | | - function setupDatabase() { |
| 626 | + public function setupDatabase() { |
631 | 627 | global $wgDBprefix, $wgDBtype; |
632 | 628 | if ( $this->databaseSetupDone ) { |
633 | 629 | return; |
— | — | @@ -771,7 +767,7 @@ |
772 | 768 | $db->tablePrefix( $prefix ); |
773 | 769 | } |
774 | 770 | |
775 | | - private function teardownDatabase() { |
| 771 | + public function teardownDatabase() { |
776 | 772 | global $wgDBtype; |
777 | 773 | if ( !$this->databaseSetupDone ) { |
778 | 774 | return; |
— | — | @@ -1146,6 +1142,11 @@ |
1147 | 1143 | $this->term->color( 0 ); |
1148 | 1144 | return "$display\n$caret"; |
1149 | 1145 | } |
| 1146 | + |
| 1147 | + function getFakeTimestamp( &$parser, &$ts ) { |
| 1148 | + $ts = 123; |
| 1149 | + return true; |
| 1150 | + } |
1150 | 1151 | } |
1151 | 1152 | |
1152 | 1153 | class AnsiTermColorer { |
— | — | @@ -1733,3 +1734,4 @@ |
1734 | 1735 | return false; |
1735 | 1736 | } |
1736 | 1737 | } |
| 1738 | + |
Index: trunk/phase3/maintenance/parserTests.php |
— | — | @@ -22,9 +22,12 @@ |
23 | 23 | * @ingroup Maintenance |
24 | 24 | */ |
25 | 25 | |
26 | | -/** */ |
27 | | -require( 'parserTests.inc' ); |
| 26 | +$options = array( 'quick', 'color', 'quiet', 'help', 'show-output', 'record', 'run-disabled' ); |
| 27 | +$optionsWithArgs = array( 'regex', 'seed', 'setversion' ); |
28 | 28 | |
| 29 | +require_once( dirname( __FILE__ ) . '/commandLine.inc' ); |
| 30 | +require_once( dirname( __FILE__ ) . '/parserTests.inc' ); |
| 31 | + |
29 | 32 | if ( isset( $options['help'] ) ) { |
30 | 33 | echo <<<ENDS |
31 | 34 | MediaWiki $wgVersion parser test suite |
Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -1995,15 +1995,6 @@ |
1996 | 1996 | !! end |
1997 | 1997 | |
1998 | 1998 | !! test |
1999 | | -Magic Word: {{NUMBEROFARTICLES}} |
2000 | | -!! input |
2001 | | -{{NUMBEROFARTICLES}} |
2002 | | -!! result |
2003 | | -<p>2 |
2004 | | -</p> |
2005 | | -!! end |
2006 | | - |
2007 | | -!! test |
2008 | 1999 | Magic Word: {{NUMBEROFFILES}} |
2009 | 2000 | !! input |
2010 | 2001 | {{NUMBEROFFILES}} |
Index: trunk/phase3/maintenance/tests/SearchEngineTest.php |
— | — | @@ -1,11 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once( 'MediaWiki_Setup.php' ); |
5 | | - |
6 | 4 | /** |
7 | 5 | * @group Stub |
8 | 6 | */ |
9 | | -class SearchEngineTest extends MediaWiki_Setup { |
| 7 | +class SearchEngineTest extends MediaWikiTestSetup { |
10 | 8 | var $db, $search, $pageList; |
11 | 9 | |
12 | 10 | function pageExists( $title ) { |
Index: trunk/phase3/maintenance/tests/ApiWatchTest.php |
— | — | @@ -1,10 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -global $IP; |
5 | | -require_once( "$IP/maintenance/tests/ApiSetup.php" ); |
| 4 | +class ApiWatchTest extends ApiTestSetup { |
6 | 5 | |
7 | | -class ApiWatchTest extends ApiSetup { |
8 | | - |
9 | 6 | function setUp() { |
10 | 7 | ini_set( 'log_errors', 1 ); |
11 | 8 | ini_set( 'error_reporting', 1 ); |
Index: trunk/phase3/maintenance/tests/phpunit |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +#!/usr/bin/env php |
| 3 | +<?php |
| 4 | + |
| 5 | +require( dirname( __FILE__ ) . '/../commandLine.inc' ); |
| 6 | +require 'PHPUnit/TextUI/Command.php'; |
| 7 | +define( 'MW_PHPUNIT_TEST', 1 ); |
| 8 | + |
| 9 | +$wgLocaltimezone = 'UTC'; |
| 10 | + |
| 11 | +/* Tests were failing with sqlite */ |
| 12 | +global $wgCaches; |
| 13 | +$wgCaches[CACHE_DB] = false; |
| 14 | + |
| 15 | +if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) { |
| 16 | + echo <<<EOF |
| 17 | +************************************************************ |
| 18 | + |
| 19 | +These tests run best with version PHPUnit 3.4.2 or later. |
| 20 | +Earlier versions may show failures because earlier versions |
| 21 | +of PHPUnit do not properly implement dependencies. |
| 22 | + |
| 23 | +************************************************************ |
| 24 | + |
| 25 | +EOF; |
| 26 | +} |
| 27 | + |
| 28 | +$command = new PHPUnit_TextUI_Command; |
| 29 | +$command->run( $argv ); |
| 30 | + |
Property changes on: trunk/phase3/maintenance/tests/phpunit |
___________________________________________________________________ |
Name: svn:executable |
1 | 31 | + * |
Index: trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php |
— | — | @@ -1,7 +1,5 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once( 'UploadFromUrlTest.php' ); |
5 | | - |
6 | 4 | class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite |
7 | 5 | { |
8 | 6 | public static function addTables( &$tables ) { |
Index: trunk/phase3/maintenance/tests/ApiTest.php |
— | — | @@ -1,7 +1,5 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once( "ApiSetup.php" ); |
5 | | - |
6 | 4 | class MockApi extends ApiBase { |
7 | 5 | public function execute() { } |
8 | 6 | public function getVersion() { } |
— | — | @@ -20,7 +18,7 @@ |
21 | 19 | } |
22 | 20 | |
23 | 21 | |
24 | | -class ApiTest extends ApiSetup { |
| 22 | +class ApiTest extends ApiTestSetup { |
25 | 23 | |
26 | 24 | function setup() { |
27 | 25 | parent::setup(); |
Index: trunk/phase3/maintenance/tests/SearchDbTest.php |
— | — | @@ -1,6 +1,4 @@ |
2 | 2 | <?php |
3 | | -require_once( 'SearchEngineTest.php' ); |
4 | | - |
5 | 3 | class SearchDbTest extends SearchEngineTest { |
6 | 4 | var $db; |
7 | 5 | |
Index: trunk/phase3/maintenance/tests/bootstrap.php |
— | — | @@ -1,32 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/** |
5 | | - * Set up the MediaWiki environment when running tests with "phpunit" command |
6 | | - * |
7 | | - * Warning: this file is not included from global scope! |
8 | | - * @file |
9 | | - */ |
10 | | - |
11 | | -global $wgCommandLineMode, $IP, $optionsWithArgs; |
12 | | -$IP = dirname( dirname( dirname( __FILE__ ) ) ); |
13 | | -define( 'MW_PHPUNIT_TEST', true ); |
14 | | - |
15 | | -require_once( "$IP/maintenance/commandLine.inc" ); |
16 | | -$wgLocaltimezone = 'UTC'; |
17 | | - |
18 | | -/* Tests were failing with sqlite */ |
19 | | -global $wgCaches; |
20 | | -$wgCaches[CACHE_DB] = false; |
21 | | - |
22 | | -if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) { |
23 | | - echo <<<EOF |
24 | | -************************************************************ |
25 | | - |
26 | | -These tests run best with version PHPUnit 3.4.2 or better. |
27 | | -Earlier versions may show failures because earlier versions |
28 | | -of PHPUnit do not properly implement dependencies. |
29 | | - |
30 | | -************************************************************ |
31 | | - |
32 | | -EOF; |
33 | | -} |
\ No newline at end of file |
| 4 | +if ( !defined( 'MW_PHPUNIT_TEST' ) ) { |
| 5 | + echo "Please run PHPUnit via maintenance/tests/phpunit\n"; |
| 6 | + exit( 1 ); |
| 7 | +} |
Index: trunk/phase3/maintenance/tests/ParserHelpers.php |
— | — | @@ -0,0 +1,84 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ParserUnitTest extends PHPUnit_Framework_TestCase { |
| 5 | + private $test = ""; |
| 6 | + private $suite; |
| 7 | + |
| 8 | + public function __construct( $suite, $test = null ) { |
| 9 | + $this->suite = $suite; |
| 10 | + $this->test = $test; |
| 11 | + } |
| 12 | + |
| 13 | + function count() { return 1; } |
| 14 | + |
| 15 | + public function run( PHPUnit_Framework_TestResult $result = null ) { |
| 16 | + PHPUnit_Framework_Assert::resetCount(); |
| 17 | + if ( $result === NULL ) { |
| 18 | + $result = new PHPUnit_Framework_TestResult; |
| 19 | + } |
| 20 | + |
| 21 | + $backend = $this->suite->getBackend(); |
| 22 | + $result->startTest( $this ); |
| 23 | + PHPUnit_Util_Timer::start(); |
| 24 | + |
| 25 | + $r = false; |
| 26 | + try { |
| 27 | + # Run the test. |
| 28 | + # On failure, the subclassed backend will throw an exception with |
| 29 | + # the details. |
| 30 | + $r = $backend->runTest( |
| 31 | + $this->test['test'], |
| 32 | + $this->test['input'], |
| 33 | + $this->test['result'], |
| 34 | + $this->test['options'], |
| 35 | + $this->test['config'] |
| 36 | + ); |
| 37 | + } |
| 38 | + catch ( PHPUnit_Framework_AssertionFailedError $e ) { |
| 39 | + $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() ); |
| 40 | + } |
| 41 | + catch ( Exception $e ) { |
| 42 | + $result->addError( $this, $e, PHPUnit_Util_Timer::stop() ); |
| 43 | + } |
| 44 | + |
| 45 | + $result->endTest( $this, PHPUnit_Util_Timer::stop() ); |
| 46 | + |
| 47 | + $backend->recorder->record( $this->test['test'], $r ); |
| 48 | + $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() ); |
| 49 | + |
| 50 | + return $result; |
| 51 | + } |
| 52 | + |
| 53 | +} |
| 54 | + |
| 55 | +class ParserTestSuiteBackend extends ParserTest { |
| 56 | + function showTesting( $desc ) { |
| 57 | + } |
| 58 | + |
| 59 | + function showRunFile( $path ) { |
| 60 | + } |
| 61 | + |
| 62 | + function showSuccess( $desc ) { |
| 63 | + PHPUnit_Framework_Assert::assertTrue( true, $desc ); |
| 64 | + return true; |
| 65 | + } |
| 66 | + |
| 67 | + function showFailure( $desc, $expected, $got ) { |
| 68 | + PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc ); |
| 69 | + } |
| 70 | + |
| 71 | + public function setupRecorder() { |
| 72 | + $this->recorder = new PHPUnitTestRecorder( $this ); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +class PHPUnitTestRecorder extends TestRecorder { |
| 77 | + function record( $test, $result ) { |
| 78 | + $this->total++; |
| 79 | + $this->success += $result; |
| 80 | + |
| 81 | + } |
| 82 | + |
| 83 | + function reportPercentage( $success, $total ) { } |
| 84 | +} |
| 85 | + |
Property changes on: trunk/phase3/maintenance/tests/ParserHelpers.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 86 | + native |
Index: trunk/phase3/maintenance/tests/Makefile |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | all test: tap |
8 | 8 | |
9 | 9 | tap: |
10 | | - prove -e 'phpunit --tap' *Test*.php |
| 10 | + prove -e 'php phpunit.php --tap' *Test*.php |
11 | 11 | |
12 | 12 | phpunit: |
13 | 13 | phpunit |
Index: trunk/phase3/maintenance/tests/ApiSetup.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -abstract class ApiSetup extends PHPUnit_Framework_TestCase { |
| 4 | +abstract class ApiTestSetup extends PHPUnit_Framework_TestCase { |
5 | 5 | protected static $userName; |
6 | 6 | protected static $passWord; |
7 | 7 | protected static $user; |
Index: trunk/phase3/maintenance/tests/UploadFromUrlTest.php |
— | — | @@ -1,16 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -global $IP; |
5 | | -require_once( "ApiSetup.php" ); |
6 | | -require_once( dirname( dirname( __FILE__ ) ) . "/deleteArchivedFiles.inc" ); |
7 | | -require_once( dirname( dirname( __FILE__ ) ) . "/deleteArchivedRevisions.inc" ); |
8 | | - |
9 | 4 | class nullClass { |
10 | 5 | public function handleOutput() { } |
11 | 6 | public function purgeRedundantText() { } |
12 | 7 | } |
13 | 8 | |
14 | | -class UploadFromUrlTest extends ApiSetup { |
| 9 | +class UploadFromUrlTest extends ApiTestSetup { |
15 | 10 | |
16 | 11 | function setUp() { |
17 | 12 | global $wgEnableUploads, $wgLocalFileRepo, $wgAllowCopyUploads; |
Index: trunk/phase3/maintenance/tests/phpunit.xml |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | <file>DatabaseSqliteTest.php</file> |
16 | 16 | <file>DatabaseTest.php</file> |
17 | 17 | <file>GlobalTest.php</file> |
18 | | - <file>HttpTest.php</file> |
| 18 | + <!--<file>HttpTest.php</file>--> |
19 | 19 | <file>IPTest.php</file> |
20 | 20 | <file>ImageFunctionsTest.php</file> |
21 | 21 | <file>LanguageConverterTest.php</file> |
— | — | @@ -41,4 +41,4 @@ |
42 | 42 | <group>Stub</group> |
43 | 43 | </exclude> |
44 | 44 | </groups> |
45 | | -</phpunit> |
\ No newline at end of file |
| 45 | +</phpunit> |
Index: trunk/phase3/maintenance/tests/MediaWikiParserTest.php |
— | — | @@ -1,302 +1,52 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -global $IP; |
5 | | -define( "NO_COMMAND_LINE", 1 ); |
6 | | -define( "PARSER_TESTS", "$IP/maintenance/parserTests.txt" ); |
7 | | - |
8 | | -require_once( "$IP/maintenance/parserTests.inc" ); |
9 | | - |
10 | | -class PHPUnitTestRecorder extends TestRecorder { |
11 | | - |
12 | | - function record( $test, $result ) { |
13 | | - $this->total++; |
14 | | - $this->success += $result; |
15 | | - |
16 | | - } |
17 | | - |
18 | | - function reportPercentage( $success, $total ) { } |
19 | | -} |
20 | | - |
21 | 4 | class MediaWikiParserTestSuite extends PHPUnit_Framework_TestSuite { |
22 | | - static private $count; |
23 | | - static public $parser; |
24 | | - static public $iter; |
| 5 | + private $count; |
| 6 | + public $backend; |
25 | 7 | |
26 | | - public static function addTables( &$tables ) { |
27 | | - $tables[] = 'user_properties'; |
28 | | - $tables[] = 'filearchive'; |
29 | | - $tables[] = 'logging'; |
30 | | - $tables[] = 'updatelog'; |
31 | | - $tables[] = 'iwlinks'; |
32 | | - $tables[] = 'searchindex'; |
33 | | - return true; |
34 | | - } |
35 | | - |
36 | 8 | public static function suite() { |
37 | | - $suite = new PHPUnit_Framework_TestSuite(); |
38 | | - |
39 | | - global $wgHooks; |
40 | | - $wgHooks['ParserTestTables'][] = "MediaWikiParserTestSuite::addTables"; |
41 | | - |
42 | | - self::$iter = new TestFileIterator( PARSER_TESTS ); |
43 | | - |
44 | | - foreach ( self::$iter as $i => $test ) { |
45 | | - $suite->addTest( new ParserUnitTest( $i, $test['test'] ) ); |
46 | | - self::$count++; |
47 | | - } |
48 | | - unset( $tests ); |
49 | | - |
50 | | - self::$parser = new PTShell; |
51 | | - self::$iter->setParser( self::$parser ); |
52 | | - self::$parser->recorder->start(); |
53 | | - self::$parser->setupDatabase(); |
54 | | - self::$iter->rewind(); |
55 | | - /* } */ |
56 | | - /* function setUp() { */ |
57 | | - global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, |
58 | | - $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, |
59 | | - $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, |
60 | | - $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, |
61 | | - $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath, |
62 | | - $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath; |
63 | | - |
64 | | - $wgScript = '/index.php'; |
65 | | - $wgScriptPath = '/'; |
66 | | - $wgArticlePath = '/wiki/$1'; |
67 | | - $wgStyleSheetPath = '/skins'; |
68 | | - $wgStylePath = '/skins'; |
69 | | - $wgThumbnailScriptPath = false; |
70 | | - $wgLocalFileRepo = array( |
71 | | - 'class' => 'LocalRepo', |
72 | | - 'name' => 'local', |
73 | | - 'directory' => 'test-repo', |
74 | | - 'url' => 'http://example.com/images', |
75 | | - 'hashLevels' => 2, |
76 | | - 'transformVia404' => false, |
77 | | - ); |
78 | | - $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface'; |
79 | | - $wgNamespaceAliases['Image'] = NS_FILE; |
80 | | - $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; |
81 | | - |
82 | | - |
83 | | - $wgEnableParserCache = false; |
84 | | - $wgDeferredUpdateList = array(); |
85 | | - $wgMemc =& wfGetMainCache(); |
86 | | - $messageMemc =& wfGetMessageCacheStorage(); |
87 | | - $parserMemc =& wfGetParserCacheStorage(); |
88 | | - |
89 | | - $wgContLang = new StubContLang; |
90 | | - $wgUser = new StubUser; |
91 | | - $wgLang = new StubUserLang; |
92 | | - $wgOut = new StubObject( 'wgOut', 'OutputPage' ); |
93 | | - $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) ); |
94 | | - $wgRequest = new WebRequest; |
95 | | - |
96 | | - $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache', |
97 | | - array( $messageMemc, $wgUseDatabaseMessages, |
98 | | - $wgMsgCacheExpiry, wfWikiID() ) ); |
99 | | - if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins"; |
100 | | - |
101 | | - return $suite; |
| 9 | + return new self; |
102 | 10 | } |
103 | 11 | |
104 | | - public function tearDown() { |
105 | | - /* $this->teardownDatabase(); */ |
106 | | - $this->recorder->report(); |
107 | | - $this->recorder->end(); |
108 | | - $this->teardownUploadDir( $this->uploadDir ); |
| 12 | + public function __construct() { |
| 13 | + $this->backend = new ParserTestSuiteBackend; |
| 14 | + parent::__construct(); |
109 | 15 | } |
110 | 16 | |
111 | | - public function count() { return self::$count; } |
112 | | - |
113 | | - public function toString() { |
114 | | - return "MediaWiki Parser Tests"; |
115 | | - } |
116 | | - |
117 | | - |
118 | | - private $uploadDir; |
119 | | - private $keepUploads; |
120 | | - |
121 | | - /** |
122 | | - * Remove the dummy uploads directory |
123 | | - */ |
124 | | - private function teardownUploadDir( $dir ) { |
125 | | - if ( $this->keepUploads ) { |
126 | | - return; |
127 | | - } |
128 | | - |
129 | | - // delete the files first, then the dirs. |
130 | | - self::deleteFiles( |
131 | | - array ( |
132 | | - "$dir/3/3a/Foobar.jpg", |
133 | | - "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg", |
134 | | - "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg", |
135 | | - "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg", |
136 | | - "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg", |
137 | | - |
138 | | - "$dir/0/09/Bad.jpg", |
139 | | - ) |
140 | | - ); |
141 | | - |
142 | | - self::deleteDirs( |
143 | | - array ( |
144 | | - "$dir/3/3a", |
145 | | - "$dir/3", |
146 | | - "$dir/thumb/6/65", |
147 | | - "$dir/thumb/6", |
148 | | - "$dir/thumb/3/3a/Foobar.jpg", |
149 | | - "$dir/thumb/3/3a", |
150 | | - "$dir/thumb/3", |
151 | | - |
152 | | - "$dir/0/09/", |
153 | | - "$dir/0/", |
154 | | - |
155 | | - "$dir/thumb", |
156 | | - "$dir", |
157 | | - ) |
158 | | - ); |
159 | | - } |
160 | | - |
161 | | - /** |
162 | | - * Delete the specified files, if they exist. |
163 | | - * |
164 | | - * @param $files Array: full paths to files to delete. |
165 | | - */ |
166 | | - private static function deleteFiles( $files ) { |
167 | | - foreach ( $files as $file ) { |
168 | | - if ( file_exists( $file ) ) { |
169 | | - unlink( $file ); |
170 | | - } |
171 | | - } |
172 | | - } |
173 | | - |
174 | | - /** |
175 | | - * Delete the specified directories, if they exist. Must be empty. |
176 | | - * |
177 | | - * @param $dirs Array: full paths to directories to delete. |
178 | | - */ |
179 | | - private static function deleteDirs( $dirs ) { |
180 | | - foreach ( $dirs as $dir ) { |
181 | | - if ( is_dir( $dir ) ) { |
182 | | - rmdir( $dir ); |
183 | | - } |
184 | | - } |
185 | | - } |
186 | | - |
187 | | - /** |
188 | | - * Create a dummy uploads directory which will contain a couple |
189 | | - * of files in order to pass existence tests. |
190 | | - * |
191 | | - * @return String: the directory |
192 | | - */ |
193 | | - private function setupUploadDir() { |
| 17 | + public function run( PHPUnit_Framework_TestResult $result = null, $filter = false, |
| 18 | + array $groups = array(), array $excludeGroups = array(), $processIsolation = false |
| 19 | + ) { |
194 | 20 | global $IP; |
195 | | - if ( $this->keepUploads ) { |
196 | | - $dir = wfTempDir() . '/mwParser-images'; |
197 | | - if ( is_dir( $dir ) ) { |
198 | | - return $dir; |
199 | | - } |
200 | | - } else { |
201 | | - $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images"; |
202 | | - } |
| 21 | + $this->backend->setupDatabase(); |
203 | 22 | |
204 | | - wfDebug( "Creating upload directory $dir\n" ); |
205 | | - if ( file_exists( $dir ) ) { |
206 | | - wfDebug( "Already exists!\n" ); |
207 | | - return $dir; |
208 | | - } |
209 | | - wfMkdirParents( $dir . '/3/3a' ); |
210 | | - copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" ); |
| 23 | + $iter = new TestFileIterator( "$IP/maintenance/parserTests.txt" ); |
| 24 | + $iter->setParser( $this->backend ); |
| 25 | + $this->count = 0; |
211 | 26 | |
212 | | - wfMkdirParents( $dir . '/0/09' ); |
213 | | - copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" ); |
214 | | - return $dir; |
215 | | - } |
216 | | -} |
217 | | - |
218 | | -/** |
219 | | - * @group Stub |
220 | | - */ |
221 | | -class ParserUnitTest extends PHPUnit_Framework_TestCase { |
222 | | - private $number = 0; |
223 | | - private $test = ""; |
224 | | - |
225 | | - public function testBogus() { |
226 | | - $this->markTestSkipped( "This is a stub" ); |
227 | | - } |
228 | | - |
229 | | - public function __construct( $number = null, $test = null ) { |
230 | | - $this->number = $number; |
231 | | - $this->test = $test; |
232 | | - } |
233 | | - |
234 | | - function count() { return 1; } |
235 | | - |
236 | | - public function run( PHPUnit_Framework_TestResult $result = NULL ) { |
237 | | - PHPUnit_Framework_Assert::resetCount(); |
238 | | - if ( $result === NULL ) { |
239 | | - $result = new PHPUnit_Framework_TestResult; |
240 | | - } |
241 | | - |
242 | | - $t = MediaWikiParserTestSuite::$iter->current(); |
243 | | - $k = MediaWikiParserTestSuite::$iter->key(); |
244 | | - |
245 | | - if ( !MediaWikiParserTestSuite::$iter->valid() ) { |
246 | | - return; |
| 27 | + foreach ( $iter as $test ) { |
| 28 | + $this->addTest( new ParserUnitTest( $this, $test ) ); |
| 29 | + $this->count++; |
247 | 30 | } |
248 | 31 | |
249 | | - // The only way this should happen is if the parserTest.txt |
250 | | - // file were modified while the script is running. |
251 | | - if ( $k != $this->number ) { |
252 | | - $i = $this->number; |
253 | | - wfDie( "I got confused!\n" ); |
254 | | - } |
| 32 | + parent::run( $result, $filter, $groups, $excludeGroups, $processIsolation ); |
255 | 33 | |
256 | | - $result->startTest( $this ); |
257 | | - PHPUnit_Util_Timer::start(); |
258 | | - |
259 | | - $r = false; |
260 | | - try { |
261 | | - $r = MediaWikiParserTestSuite::$parser->runTest( |
262 | | - $t['test'], $t['input'], $t['result'], $t['options'], $t['config'] |
263 | | - ); |
264 | | - PHPUnit_Framework_Assert::assertTrue( true, $t['test'] ); |
265 | | - } |
266 | | - catch ( PHPUnit_Framework_AssertionFailedError $e ) { |
267 | | - $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() ); |
268 | | - } |
269 | | - catch ( Exception $e ) { |
270 | | - $result->addError( $this, $e, PHPUnit_Util_Timer::stop() ); |
271 | | - } |
272 | | - PHPUnit_Framework_Assert::assertTrue( true, $t['test'] ); |
273 | | - |
274 | | - $result->endTest( $this, PHPUnit_Util_Timer::stop() ); |
275 | | - |
276 | | - MediaWikiParserTestSuite::$parser->recorder->record( $t['test'], $r ); |
277 | | - MediaWikiParserTestSuite::$iter->next(); |
278 | | - $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() ); |
279 | | - |
280 | | - return $result; |
| 34 | + $this->backend->teardownDatabase(); |
281 | 35 | } |
282 | 36 | |
283 | | -} |
284 | | - |
285 | | -class PTShell extends ParserTest { |
286 | | - function showTesting( $desc ) { |
| 37 | + public function count() { |
| 38 | + return $this->count; |
287 | 39 | } |
288 | 40 | |
289 | | - function showRunFile( $path ) { |
| 41 | + public function toString() { |
| 42 | + return "MediaWiki Parser Tests"; |
290 | 43 | } |
291 | 44 | |
292 | | - function showSuccess( $desc ) { |
293 | | - PHPUnit_Framework_Assert::assertTrue( true, $desc ); |
294 | | - return true; |
| 45 | + public function getBackend() { |
| 46 | + return $this->backend; |
295 | 47 | } |
296 | 48 | |
297 | | - function showFailure( $desc, $expected, $got ) { |
298 | | - PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc ); |
| 49 | + public function getIterator() { |
| 50 | + return $this->iterator; |
299 | 51 | } |
300 | | - |
301 | 52 | } |
302 | 53 | |
303 | | - |
Index: trunk/phase3/maintenance/tests/MediaWiki_Setup.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -abstract class MediaWiki_Setup extends PHPUnit_Framework_TestCase { |
| 4 | +abstract class MediaWikiTestSetup extends PHPUnit_Framework_TestCase { |
5 | 5 | |
6 | 6 | protected function buildTestDatabase( $tables ) { |
7 | 7 | global $wgDBprefix; |
Index: trunk/phase3/maintenance/parserTestsStaticParserHook.php |
— | — | @@ -1,6 +1,4 @@ |
2 | 2 | <?php |
3 | | -if ( ! defined( 'MEDIAWIKI' ) ) |
4 | | - die( -1 ); |
5 | 3 | /** |
6 | 4 | * A basic extension that's used by the parser tests to test whether the parser |
7 | 5 | * calls extensions when they're called inside comments, it shouldn't do that |
— | — | @@ -13,35 +11,34 @@ |
14 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
15 | 13 | */ |
16 | 14 | |
17 | | -$wgHooks['ParserTestParser'][] = 'wfParserTestStaticParserHookSetup'; |
| 15 | +class ParserTestStaticParserHook { |
| 16 | + static function setup( &$parser ) { |
| 17 | + $parser->setHook( 'statictag', array( __CLASS__, 'hook' ) ); |
18 | 18 | |
19 | | -function wfParserTestStaticParserHookSetup( &$parser ) { |
20 | | - $parser->setHook( 'statictag', 'wfParserTestStaticParserHookHook' ); |
| 19 | + return true; |
| 20 | + } |
21 | 21 | |
22 | | - return true; |
| 22 | + static function hook( $in, $argv, $parser ) { |
| 23 | + if ( ! count( $argv ) ) { |
| 24 | + $parser->static_tag_buf = $in; |
| 25 | + return ''; |
| 26 | + } else if ( count( $argv ) === 1 && isset( $argv['action'] ) |
| 27 | + && $argv['action'] === 'flush' && $in === null ) |
| 28 | + { |
| 29 | + // Clear the buffer, we probably don't need to |
| 30 | + if ( isset( $parser->static_tag_buf ) ) { |
| 31 | + $tmp = $parser->static_tag_buf; |
| 32 | + } else { |
| 33 | + $tmp = ''; |
| 34 | + } |
| 35 | + $parser->static_tag_buf = null; |
| 36 | + return $tmp; |
| 37 | + } else |
| 38 | + // wtf? |
| 39 | + return |
| 40 | + "\nCall this extension as <statictag>string</statictag> or as" . |
| 41 | + " <statictag action=flush/>, not in any other way.\n" . |
| 42 | + "text: " . var_export( $in, true ) . "\n" . |
| 43 | + "argv: " . var_export( $argv, true ) . "\n"; |
| 44 | + } |
23 | 45 | } |
24 | | - |
25 | | -function wfParserTestStaticParserHookHook( $in, $argv, $parser ) { |
26 | | - if ( ! count( $argv ) ) { |
27 | | - $parser->static_tag_buf = $in; |
28 | | - return ''; |
29 | | - } else if ( count( $argv ) === 1 && isset( $argv['action'] ) |
30 | | - && $argv['action'] === 'flush' && $in === null ) |
31 | | - { |
32 | | - // Clear the buffer, we probably don't need to |
33 | | - if ( isset( $parser->static_tag_buf ) ) { |
34 | | - $tmp = $parser->static_tag_buf; |
35 | | - } else { |
36 | | - $tmp = ''; |
37 | | - } |
38 | | - $parser->static_tag_buf = null; |
39 | | - return $tmp; |
40 | | - } else |
41 | | - // wtf? |
42 | | - return |
43 | | - "\nCall this extension as <statictag>string</statictag> or as" . |
44 | | - " <statictag action=flush/>, not in any other way.\n" . |
45 | | - "text: " . var_export( $in, true ) . "\n" . |
46 | | - "argv: " . var_export( $argv, true ) . "\n"; |
47 | | -} |
48 | | - |
Index: trunk/phase3/maintenance/language/diffLanguage.php |
— | — | @@ -40,7 +40,6 @@ |
41 | 41 | */ |
42 | 42 | |
43 | 43 | /** This script run from the commandline */ |
44 | | -require_once( dirname( __FILE__ ) . '/../parserTests.inc' ); |
45 | 44 | require_once( dirname( __FILE__ ) . '/../commandLine.inc' ); |
46 | 45 | |
47 | 46 | if ( isset( $options['help'] ) ) { usage(); wfDie(); } |
Index: trunk/phase3/maintenance/parserTestsParserHook.php |
— | — | @@ -1,6 +1,4 @@ |
2 | 2 | <?php |
3 | | -if ( ! defined( 'MEDIAWIKI' ) ) |
4 | | - die( -1 ); |
5 | 3 | /** |
6 | 4 | * A basic extension that's used by the parser tests to test whether input and |
7 | 5 | * arguments are passed to extensions properly. |
— | — | @@ -13,22 +11,22 @@ |
14 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
15 | 13 | */ |
16 | 14 | |
17 | | -$wgHooks['ParserTestParser'][] = 'wfParserTestParserHookSetup'; |
| 15 | +class ParserTestParserHook { |
18 | 16 | |
19 | | -function wfParserTestParserHookSetup( &$parser ) { |
20 | | - $parser->setHook( 'tag', 'wfParserTestParserHookHook' ); |
| 17 | + static function setup( &$parser ) { |
| 18 | + $parser->setHook( 'tag', array( __CLASS__, 'hook' ) ); |
21 | 19 | |
22 | | - return true; |
23 | | -} |
| 20 | + return true; |
| 21 | + } |
24 | 22 | |
25 | | -function wfParserTestParserHookHook( $in, $argv ) { |
26 | | - ob_start(); |
27 | | - var_dump( |
28 | | - $in, |
29 | | - $argv |
30 | | - ); |
31 | | - $ret = ob_get_clean(); |
| 23 | + function hook( $in, $argv ) { |
| 24 | + ob_start(); |
| 25 | + var_dump( |
| 26 | + $in, |
| 27 | + $argv |
| 28 | + ); |
| 29 | + $ret = ob_get_clean(); |
32 | 30 | |
33 | | - return "<pre>\n$ret</pre>"; |
| 31 | + return "<pre>\n$ret</pre>"; |
| 32 | + } |
34 | 33 | } |
35 | | - |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -636,13 +636,31 @@ |
637 | 637 | 'FakeConverter' => 'languages/Language.php', |
638 | 638 | 'LanguageConverter' => 'languages/LanguageConverter.php', |
639 | 639 | |
640 | | - # maintenance/language |
| 640 | + # maintenance |
| 641 | + 'AnsiTermColorer' => 'maintenance/parserTests.inc', |
| 642 | + 'ApiTestSetup' => 'maintenance/tests/ApiSetup.php', |
| 643 | + 'DbTestPreviewer' => 'maintenance/parserTests.inc', |
| 644 | + 'DbTestRecorder' => 'maintenance/parserTests.inc', |
| 645 | + 'DeleteArchivedFilesImplementation' => 'maintenance/deleteArchivedFiles.inc', |
| 646 | + 'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc', |
| 647 | + 'DummyTermColorer' => 'maintenance/parserTests.inc', |
| 648 | + 'MediaWikiTestSetup' => 'maintenance/tests/MediaWiki_Setup.php', |
| 649 | + 'PHPUnitTestRecorder' => 'maintenance/tests/ParserHelpers.php', |
| 650 | + 'ParserTest' => 'maintenance/parserTests.inc', |
| 651 | + 'ParserTestParserHook' => 'maintenance/parserTestsParserHook.php', |
| 652 | + 'ParserTestStaticParserHook' => 'maintenance/parserTestsStaticParserHook.php', |
| 653 | + 'ParserTestSuiteBackend' => 'maintenance/tests/ParserHelpers.php', |
| 654 | + 'ParserUnitTest' => 'maintenance/tests/ParserHelpers.php', |
| 655 | + 'RemoteTestRecorder' => 'maintenance/parserTests.inc', |
| 656 | + 'SearchEngineTest' => 'maintenance/tests/SearchEngineTest.php', |
| 657 | + 'SevenZipStream' => 'maintenance/7zip.inc', |
| 658 | + 'TestFileIterator' => 'maintenance/parserTests.inc', |
| 659 | + 'TestRecorder' => 'maintenance/parserTests.inc', |
| 660 | + 'UploadFromUrlTest' => 'maintenance/tests/UploadFromUrlTest.php', |
| 661 | + 'csvStatsOutput' => 'maintenance/language/StatOutputs.php', |
641 | 662 | 'statsOutput' => 'maintenance/language/StatOutputs.php', |
| 663 | + 'textStatsOutput' => 'maintenance/language/StatOutputs.php', |
642 | 664 | 'wikiStatsOutput' => 'maintenance/language/StatOutputs.php', |
643 | | - 'textStatsOutput' => 'maintenance/language/StatOutputs.php', |
644 | | - 'csvStatsOutput' => 'maintenance/language/StatOutputs.php', |
645 | | - 'SevenZipStream' => 'maintenance/7zip.inc', |
646 | | - |
647 | 665 | ); |
648 | 666 | |
649 | 667 | class AutoLoader { |