Index: trunk/phase3/maintenance/parserTests.inc |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | -# Copyright (C) 2004 Brion Vibber <brion@pobox.com> |
| 3 | +# Copyright (C) 2004, 2010 Brion Vibber <brion@pobox.com> |
4 | 4 | # http://www.mediawiki.org/ |
5 | 5 | # |
6 | 6 | # This program is free software; you can redistribute it and/or modify |
— | — | @@ -120,6 +120,8 @@ |
121 | 121 | $this->recorder = new DbTestPreviewer( $this ); |
122 | 122 | } elseif( isset( $options['upload'] ) ) { |
123 | 123 | $this->recorder = new RemoteTestRecorder( $this ); |
| 124 | + } elseif( class_exists( 'PHPUnitTestRecorder' ) ) { |
| 125 | + $this->recorder = new PHPUnitTestRecorder( $this ); |
124 | 126 | } else { |
125 | 127 | $this->recorder = new TestRecorder( $this ); |
126 | 128 | } |
— | — | @@ -138,7 +140,7 @@ |
139 | 141 | /** |
140 | 142 | * Remove last character if it is a newline |
141 | 143 | */ |
142 | | - private function chomp($s) { |
| 144 | + public function chomp($s) { |
143 | 145 | if (substr($s, -1) === "\n") { |
144 | 146 | return substr($s, 0, -1); |
145 | 147 | } |
— | — | @@ -276,7 +278,8 @@ |
277 | 279 | $this->setupDatabase(); |
278 | 280 | $ok = true; |
279 | 281 | foreach( $filenames as $filename ) { |
280 | | - $ok = $this->runFile( $filename ) && $ok; |
| 282 | + $tests = new TestFileIterator( $filename, $this ); |
| 283 | + $ok = $this->runTests( $tests ) && $ok; |
281 | 284 | } |
282 | 285 | $this->teardownDatabase(); |
283 | 286 | $this->recorder->report(); |
— | — | @@ -284,124 +287,17 @@ |
285 | 288 | return $ok; |
286 | 289 | } |
287 | 290 | |
288 | | - private function runFile( $filename ) { |
289 | | - $infile = fopen( $filename, 'rt' ); |
290 | | - if( !$infile ) { |
291 | | - wfDie( "Couldn't open file '$filename'\n" ); |
292 | | - } else { |
293 | | - global $IP; |
294 | | - $relative = wfRelativePath( $filename, $IP ); |
295 | | - $this->showRunFile( $relative ); |
296 | | - } |
297 | | - |
298 | | - $data = array(); |
299 | | - $section = null; |
300 | | - $n = 0; |
| 291 | + function runTests($tests) { |
301 | 292 | $ok = true; |
302 | | - while( false !== ($line = fgets( $infile ) ) ) { |
303 | | - $n++; |
304 | | - $matches = array(); |
305 | | - if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) { |
306 | | - $section = strtolower( $matches[1] ); |
307 | | - if( $section == 'endarticle') { |
308 | | - if( !isset( $data['text'] ) ) { |
309 | | - wfDie( "'endarticle' without 'text' at line $n of $filename\n" ); |
310 | | - } |
311 | | - if( !isset( $data['article'] ) ) { |
312 | | - wfDie( "'endarticle' without 'article' at line $n of $filename\n" ); |
313 | | - } |
314 | | - $this->addArticle($this->chomp($data['article']), $this->chomp($data['text']), $n); |
315 | | - $data = array(); |
316 | | - $section = null; |
317 | | - continue; |
318 | | - } |
319 | | - if( $section == 'endhooks' ) { |
320 | | - if( !isset( $data['hooks'] ) ) { |
321 | | - wfDie( "'endhooks' without 'hooks' at line $n of $filename\n" ); |
322 | | - } |
323 | | - foreach( explode( "\n", $data['hooks'] ) as $line ) { |
324 | | - $line = trim( $line ); |
325 | | - if( $line ) { |
326 | | - $this->requireHook( $line ); |
327 | | - } |
328 | | - } |
329 | | - $data = array(); |
330 | | - $section = null; |
331 | | - continue; |
332 | | - } |
333 | | - if( $section == 'endfunctionhooks' ) { |
334 | | - if( !isset( $data['functionhooks'] ) ) { |
335 | | - wfDie( "'endfunctionhooks' without 'functionhooks' at line $n of $filename\n" ); |
336 | | - } |
337 | | - foreach( explode( "\n", $data['functionhooks'] ) as $line ) { |
338 | | - $line = trim( $line ); |
339 | | - if( $line ) { |
340 | | - $this->requireFunctionHook( $line ); |
341 | | - } |
342 | | - } |
343 | | - $data = array(); |
344 | | - $section = null; |
345 | | - continue; |
346 | | - } |
347 | | - if( $section == 'end' ) { |
348 | | - if( !isset( $data['test'] ) ) { |
349 | | - wfDie( "'end' without 'test' at line $n of $filename\n" ); |
350 | | - } |
351 | | - if( !isset( $data['input'] ) ) { |
352 | | - wfDie( "'end' without 'input' at line $n of $filename\n" ); |
353 | | - } |
354 | | - if( !isset( $data['result'] ) ) { |
355 | | - wfDie( "'end' without 'result' at line $n of $filename\n" ); |
356 | | - } |
357 | | - if( !isset( $data['options'] ) ) { |
358 | | - $data['options'] = ''; |
359 | | - } |
360 | | - else { |
361 | | - $data['options'] = $this->chomp( $data['options'] ); |
362 | | - } |
363 | | - if (!isset( $data['config'] ) ) |
364 | | - $data['config'] = ''; |
365 | | - |
366 | | - if ( (preg_match('/\\bdisabled\\b/i', $data['options']) |
367 | | - || !preg_match("/{$this->regex}/i", $data['test'])) && !$this->runDisabled ) { |
368 | | - # disabled test |
369 | | - $data = array(); |
370 | | - $section = null; |
371 | | - continue; |
372 | | - } |
373 | | - if ( preg_match('/\\bmath\\b/i', $data['options']) && !$this->savedGlobals['wgUseTeX'] ) { |
374 | | - # don't run math tests if $wgUseTeX is set to false in LocalSettings |
375 | | - $data = array(); |
376 | | - $section = null; |
377 | | - continue; |
378 | | - } |
379 | | - $result = $this->runTest( |
380 | | - $this->chomp( $data['test'] ), |
381 | | - $this->chomp( $data['input'] ), |
382 | | - $this->chomp( $data['result'] ), |
383 | | - $this->chomp( $data['options'] ), |
384 | | - $this->chomp( $data['config'] ) |
385 | | - ); |
386 | | - $ok = $ok && $result; |
387 | | - $this->recorder->record( $this->chomp( $data['test'] ), $result ); |
388 | | - $data = array(); |
389 | | - $section = null; |
390 | | - continue; |
391 | | - } |
392 | | - if ( isset ($data[$section] ) ) { |
393 | | - wfDie( "duplicate section '$section' at line $n of $filename\n" ); |
394 | | - } |
395 | | - $data[$section] = ''; |
396 | | - continue; |
397 | | - } |
398 | | - if( $section ) { |
399 | | - $data[$section] .= $line; |
400 | | - } |
| 293 | + foreach($tests as $i => $t) { |
| 294 | + $result = |
| 295 | + $this->runTest($t['test'], $t['input'], $t['result'], $t['options'], $t['config']); |
| 296 | + $ok = $ok && $result; |
| 297 | + $this->recorder->record( $t['test'], $result ); |
401 | 298 | } |
402 | 299 | if ( $this->showProgress ) { |
403 | 300 | print "\n"; |
404 | 301 | } |
405 | | - return $ok; |
406 | 302 | } |
407 | 303 | |
408 | 304 | /** |
— | — | @@ -431,7 +327,7 @@ |
432 | 328 | * @param string $result Result to output |
433 | 329 | * @return bool |
434 | 330 | */ |
435 | | - private function runTest( $desc, $input, $result, $opts, $config ) { |
| 331 | + public function runTest( $desc, $input, $result, $opts, $config ) { |
436 | 332 | if( $this->showProgress ) { |
437 | 333 | $this->showTesting( $desc ); |
438 | 334 | } |
— | — | @@ -722,7 +618,7 @@ |
723 | 619 | * Currently this will only be done once per run, and any changes to |
724 | 620 | * the db will be visible to later tests in the run. |
725 | 621 | */ |
726 | | - private function setupDatabase() { |
| 622 | + function setupDatabase() { |
727 | 623 | global $wgDBprefix, $wgDBtype; |
728 | 624 | if ( $this->databaseSetupDone ) { |
729 | 625 | return; |
— | — | @@ -1111,7 +1007,7 @@ |
1112 | 1008 | * |
1113 | 1009 | * @param String $path |
1114 | 1010 | */ |
1115 | | - protected function showRunFile( $path ){ |
| 1011 | + public function showRunFile( $path ){ |
1116 | 1012 | print $this->term->color( 1 ) . |
1117 | 1013 | "Reading tests from \"$path\"..." . |
1118 | 1014 | $this->term->reset() . |
— | — | @@ -1124,7 +1020,7 @@ |
1125 | 1021 | * @param string $text the article text |
1126 | 1022 | * @param int $line the input line number, for reporting errors |
1127 | 1023 | */ |
1128 | | - private function addArticle($name, $text, $line) { |
| 1024 | + public function addArticle($name, $text, $line) { |
1129 | 1025 | $this->setupGlobals(); |
1130 | 1026 | $title = Title::newFromText( $name ); |
1131 | 1027 | if ( is_null($title) ) { |
— | — | @@ -1148,7 +1044,7 @@ |
1149 | 1045 | * die a painful dead to warn the others. |
1150 | 1046 | * @param string $name |
1151 | 1047 | */ |
1152 | | - private function requireHook( $name ) { |
| 1048 | + public function requireHook( $name ) { |
1153 | 1049 | global $wgParser; |
1154 | 1050 | $wgParser->firstCallInit( ); //make sure hooks are loaded. |
1155 | 1051 | if( isset( $wgParser->mTagHooks[$name] ) ) { |
— | — | @@ -1652,3 +1548,171 @@ |
1653 | 1549 | return Http::post( $url, array( 'postData' => $data) ); |
1654 | 1550 | } |
1655 | 1551 | } |
| 1552 | + |
| 1553 | +class TestFileIterator implements Iterator { |
| 1554 | + private $file; |
| 1555 | + private $fh; |
| 1556 | + private $parser; |
| 1557 | + private $index = 0; |
| 1558 | + private $test; |
| 1559 | + private $lineNum; |
| 1560 | + private $eof; |
| 1561 | + |
| 1562 | + function __construct( $file, $parser = null ) { |
| 1563 | + global $IP; |
| 1564 | + |
| 1565 | + $this->file = $file; |
| 1566 | + $this->fh = fopen($this->file, "r"); |
| 1567 | + if( !$this->fh ) { |
| 1568 | + wfDie( "Couldn't open file '$file'\n" ); |
| 1569 | + } |
| 1570 | + |
| 1571 | + $this->parser = $parser; |
| 1572 | + |
| 1573 | + if( $this->parser ) $this->parser->showRunFile( wfRelativePath( $this->file, $IP ) ); |
| 1574 | + $this->lineNum = $this->index = 0; |
| 1575 | + } |
| 1576 | + |
| 1577 | + function setParser( ParserTest $parser ) { |
| 1578 | + $this->parser = $parser; |
| 1579 | + } |
| 1580 | + |
| 1581 | + function rewind() { |
| 1582 | + if(fseek($this->fh, 0)) { |
| 1583 | + wfDie( "Couldn't fseek to the start of '$filename'\n" ); |
| 1584 | + } |
| 1585 | + $this->index = 0; |
| 1586 | + $this->lineNum = 0; |
| 1587 | + $this->eof = false; |
| 1588 | + $this->readNextTest(); |
| 1589 | + |
| 1590 | + return true; |
| 1591 | + } |
| 1592 | + |
| 1593 | + function current() { |
| 1594 | + return $this->test; |
| 1595 | + } |
| 1596 | + |
| 1597 | + function key() { |
| 1598 | + return $this->index; |
| 1599 | + } |
| 1600 | + |
| 1601 | + function next() { |
| 1602 | + if($this->readNextTest()) { |
| 1603 | + $this->index++; |
| 1604 | + return true; |
| 1605 | + } else { |
| 1606 | + $this->eof = true; |
| 1607 | + } |
| 1608 | + } |
| 1609 | + |
| 1610 | + function valid() { |
| 1611 | + return $this->eof != true; |
| 1612 | + } |
| 1613 | + |
| 1614 | + function readNextTest() { |
| 1615 | + $data = array(); |
| 1616 | + $section = null; |
| 1617 | + |
| 1618 | + while( false !== ($line = fgets( $this->fh ) ) ) { |
| 1619 | + $this->lineNum++; |
| 1620 | + $matches = array(); |
| 1621 | + if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) { |
| 1622 | + $section = strtolower( $matches[1] ); |
| 1623 | + if( $section == 'endarticle') { |
| 1624 | + if( !isset( $data['text'] ) ) { |
| 1625 | + wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $filename\n" ); |
| 1626 | + } |
| 1627 | + if( !isset( $data['article'] ) ) { |
| 1628 | + wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $filename\n" ); |
| 1629 | + } |
| 1630 | + if( $this->parser ) $this->parser->addArticle($this->parser->chomp($data['article']), $this->parser->chomp($data['text']), |
| 1631 | + $this->lineNum); |
| 1632 | + $data = array(); |
| 1633 | + $section = null; |
| 1634 | + continue; |
| 1635 | + } |
| 1636 | + if( $section == 'endhooks' ) { |
| 1637 | + if( !isset( $data['hooks'] ) ) { |
| 1638 | + wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $filename\n" ); |
| 1639 | + } |
| 1640 | + foreach( explode( "\n", $data['hooks'] ) as $line ) { |
| 1641 | + $line = trim( $line ); |
| 1642 | + if( $line ) { |
| 1643 | + if( $this->parser ) $this->parser->requireHook( $line ); |
| 1644 | + } |
| 1645 | + } |
| 1646 | + $data = array(); |
| 1647 | + $section = null; |
| 1648 | + continue; |
| 1649 | + } |
| 1650 | + if( $section == 'endfunctionhooks' ) { |
| 1651 | + if( !isset( $data['functionhooks'] ) ) { |
| 1652 | + wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $filename\n" ); |
| 1653 | + } |
| 1654 | + foreach( explode( "\n", $data['functionhooks'] ) as $line ) { |
| 1655 | + $line = trim( $line ); |
| 1656 | + if( $line ) { |
| 1657 | + if( $this->parser ) $this->parser->requireFunctionHook( $line ); |
| 1658 | + } |
| 1659 | + } |
| 1660 | + $data = array(); |
| 1661 | + $section = null; |
| 1662 | + continue; |
| 1663 | + } |
| 1664 | + if( $section == 'end' ) { |
| 1665 | + if( !isset( $data['test'] ) ) { |
| 1666 | + wfDie( "'end' without 'test' at line {$this->lineNum} of $filename\n" ); |
| 1667 | + } |
| 1668 | + if( !isset( $data['input'] ) ) { |
| 1669 | + wfDie( "'end' without 'input' at line {$this->lineNum} of $filename\n" ); |
| 1670 | + } |
| 1671 | + if( !isset( $data['result'] ) ) { |
| 1672 | + wfDie( "'end' without 'result' at line {$this->lineNum} of $filename\n" ); |
| 1673 | + } |
| 1674 | + if( !isset( $data['options'] ) ) { |
| 1675 | + $data['options'] = ''; |
| 1676 | + } |
| 1677 | + if (!isset( $data['config'] ) ) |
| 1678 | + $data['config'] = ''; |
| 1679 | + |
| 1680 | + if ( $this->parser && (preg_match('/\\bdisabled\\b/i', $data['options']) |
| 1681 | + || !preg_match("/{$this->parser->regex}/i", $data['test'])) && !$this->parser->runDisabled ) { |
| 1682 | + # disabled test |
| 1683 | + $data = array(); |
| 1684 | + $section = null; |
| 1685 | + continue; |
| 1686 | + } |
| 1687 | + if ( $this->parser && |
| 1688 | + preg_match('/\\bmath\\b/i', $data['options']) && !$this->parser->savedGlobals['wgUseTeX'] ) { |
| 1689 | + # don't run math tests if $wgUseTeX is set to false in LocalSettings |
| 1690 | + $data = array(); |
| 1691 | + $section = null; |
| 1692 | + continue; |
| 1693 | + } |
| 1694 | + |
| 1695 | + if( $this->parser ) { |
| 1696 | + $this->test = array( |
| 1697 | + 'test' => $this->parser->chomp( $data['test'] ), |
| 1698 | + 'input' => $this->parser->chomp( $data['input'] ), |
| 1699 | + 'result' => $this->parser->chomp( $data['result'] ), |
| 1700 | + 'options' => $this->parser->chomp( $data['options'] ), |
| 1701 | + 'config' => $this->parser->chomp( $data['config'] ) ); |
| 1702 | + } else { |
| 1703 | + $this->test['test'] = $data['test']; |
| 1704 | + } |
| 1705 | + return true; |
| 1706 | + } |
| 1707 | + if ( isset ($data[$section] ) ) { |
| 1708 | + wfDie( "duplicate section '$section' at line {$this->lineNum} of $filename\n" ); |
| 1709 | + } |
| 1710 | + $data[$section] = ''; |
| 1711 | + continue; |
| 1712 | + } |
| 1713 | + if( $section ) { |
| 1714 | + $data[$section] .= $line; |
| 1715 | + } |
| 1716 | + } |
| 1717 | + return false; |
| 1718 | + } |
| 1719 | +} |
\ No newline at end of file |
Index: trunk/phase3/maintenance/tests/MediaWikiParserTest.php |
— | — | @@ -2,45 +2,109 @@ |
3 | 3 | |
4 | 4 | global $IP; |
5 | 5 | define( "NO_COMMAND_LINE", 1 ); |
| 6 | +define( "PARSER_TESTS", "$IP/maintenance/parserTests.txt" ); |
| 7 | + |
6 | 8 | require_once( "$IP/maintenance/parserTests.inc" ); |
7 | | -require_once( "ImageFunctions.php" ); |
8 | | -require_once( "ProxyTools.php" ); |
9 | | -require_once( "ObjectCache.php" ); |
10 | 9 | |
11 | | -class PTShell extends ParserTest { |
| 10 | +class PHPUnitTestRecorder extends TestRecorder { |
12 | 11 | |
13 | | - private $cb; |
| 12 | + function record( $test, $result ) { |
| 13 | + $this->total++; |
| 14 | + $this->success += $result; |
14 | 15 | |
15 | | - function setCallback( $cb ) { |
16 | | - $this->cb = $cb; |
17 | 16 | } |
18 | 17 | |
19 | | - function showTesting( $desc ) { |
20 | | - } |
| 18 | + function reportPercentage( $success, $total ) {} |
| 19 | +} |
21 | 20 | |
22 | | - function showRunFile( $path ) { |
| 21 | +class MediaWikiParserTestSuite extends PHPUnit_Framework_TestSuite { |
| 22 | +#implements PHPUnit_Framework_SelfDescribing { |
| 23 | + static private $count; |
| 24 | + static public $parser; |
| 25 | + static public $iter; |
| 26 | + |
| 27 | + public static function suite() { |
| 28 | + $suite = new PHPUnit_Framework_TestSuite(); |
| 29 | + |
| 30 | + self::$iter = new TestFileIterator( PARSER_TESTS ); |
| 31 | + |
| 32 | + foreach(self::$iter as $i => $test) { |
| 33 | + $suite->addTest(new ParserUnitTest($i, $test['test'])); |
| 34 | + self::$count++; |
| 35 | + } |
| 36 | + unset($tests); |
| 37 | + |
| 38 | + self::$parser = new PTShell; |
| 39 | + self::$iter->setParser(self::$parser); |
| 40 | + self::$parser->recorder->start(); |
| 41 | + self::$parser->setupDatabase(); |
| 42 | + self::$iter->rewind(); |
| 43 | + /* } */ |
| 44 | + /* function setUp() { */ |
| 45 | + global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, |
| 46 | + $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, |
| 47 | + $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, |
| 48 | + $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, |
| 49 | + $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath, |
| 50 | + $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath; |
| 51 | + |
| 52 | + $wgScript = '/index.php'; |
| 53 | + $wgScriptPath = '/'; |
| 54 | + $wgArticlePath = '/wiki/$1'; |
| 55 | + $wgStyleSheetPath = '/skins'; |
| 56 | + $wgStylePath = '/skins'; |
| 57 | + $wgThumbnailScriptPath = false; |
| 58 | + $wgLocalFileRepo = array( |
| 59 | + 'class' => 'LocalRepo', |
| 60 | + 'name' => 'local', |
| 61 | + 'directory' => '', |
| 62 | + 'url' => 'http://example.com/images', |
| 63 | + 'hashLevels' => 2, |
| 64 | + 'transformVia404' => false, |
| 65 | + ); |
| 66 | + $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface'; |
| 67 | + $wgNamespaceAliases['Image'] = NS_FILE; |
| 68 | + $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; |
| 69 | + |
| 70 | + |
| 71 | + $wgEnableParserCache = false; |
| 72 | + $wgDeferredUpdateList = array(); |
| 73 | + $wgMemc =& wfGetMainCache(); |
| 74 | + $messageMemc =& wfGetMessageCacheStorage(); |
| 75 | + $parserMemc =& wfGetParserCacheStorage(); |
| 76 | + |
| 77 | + $wgContLang = new StubContLang; |
| 78 | + $wgUser = new StubUser; |
| 79 | + $wgLang = new StubUserLang; |
| 80 | + $wgOut = new StubObject( 'wgOut', 'OutputPage' ); |
| 81 | + $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) ); |
| 82 | + $wgRequest = new WebRequest; |
| 83 | + |
| 84 | + $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache', |
| 85 | + array( $messageMemc, $wgUseDatabaseMessages, |
| 86 | + $wgMsgCacheExpiry, wfWikiID() ) ); |
| 87 | + if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins"; |
| 88 | + |
| 89 | + return $suite; |
23 | 90 | } |
24 | 91 | |
25 | | - function showSuccess( $desc ) { |
26 | | - $this->cb->assertTrue( true, $desc ); |
27 | | - echo "PASSED: $desc\n"; |
28 | | - return true; |
| 92 | + public function tearDown() { |
| 93 | + $this->teardownDatabase(); |
| 94 | + $this->recorder->report(); |
| 95 | + $this->recorder->end(); |
| 96 | + $this->teardownUploadDir($this->uploadDir); |
29 | 97 | } |
30 | 98 | |
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"; |
| 99 | + public function count() {return self::$count;} |
| 100 | + |
| 101 | + public function toString() { |
| 102 | + return "MediaWiki Parser Tests"; |
36 | 103 | } |
37 | | -} |
38 | 104 | |
39 | | -class MediaWikiParserTest extends PHPUnit_Framework_TestCase { |
40 | | - private $parserTester; |
| 105 | + |
41 | 106 | private $db; |
42 | 107 | private $uploadDir; |
43 | 108 | private $keepUploads; |
44 | | - |
45 | 109 | /** |
46 | 110 | * Remove the dummy uploads directory |
47 | 111 | */ |
— | — | @@ -132,88 +196,84 @@ |
133 | 197 | copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" ); |
134 | 198 | return $dir; |
135 | 199 | } |
| 200 | +} |
136 | 201 | |
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; |
| 202 | +class ParserUnitTest extends PHPUnit_Framework_TestCase { |
| 203 | + private $number = 0; |
| 204 | + private $test = ""; |
143 | 205 | |
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; |
| 206 | + public function __construct($number, $test) { |
| 207 | + $this->number = $number; |
| 208 | + $this->test = $test; |
| 209 | + } |
163 | 210 | |
| 211 | + function count() {return 1;} |
164 | 212 | |
165 | | - $wgEnableParserCache = false; |
166 | | - $wgDeferredUpdateList = array(); |
167 | | - $wgMemc =& wfGetMainCache(); |
168 | | - $messageMemc =& wfGetMessageCacheStorage(); |
169 | | - $parserMemc =& wfGetParserCacheStorage(); |
| 213 | + public function run(PHPUnit_Framework_TestResult $result = NULL) { |
| 214 | + PHPUnit_Framework_Assert::resetCount(); |
| 215 | + if ($result === NULL) { |
| 216 | + $result = new PHPUnit_Framework_TestResult; |
| 217 | + } |
170 | 218 | |
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; |
| 219 | + $t = MediaWikiParserTestSuite::$iter->current(); |
| 220 | + $k = MediaWikiParserTestSuite::$iter->key(); |
177 | 221 | |
178 | | - $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache', |
179 | | - array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) ); |
180 | | - if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins"; |
| 222 | + if(!MediaWikiParserTestSuite::$iter->valid()) { |
| 223 | + return; |
| 224 | + } |
181 | 225 | |
182 | | - $this->parserTester = new PTShell(); |
183 | | - $this->parserTester->setCallback( $this ); |
| 226 | + // The only way this should happen is if the parserTest.txt |
| 227 | + // file were modified while the script is running. |
| 228 | + if($k != $this->number) { |
| 229 | + $i = $this->number; |
| 230 | + wfDie("I got confused!\n"); |
| 231 | + } |
184 | 232 | |
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; */ |
| 233 | + $result->startTest($this); |
| 234 | + PHPUnit_Util_Timer::start(); |
| 235 | + |
| 236 | + $r = false; |
| 237 | + try { |
| 238 | + $r = MediaWikiParserTestSuite::$parser->runTest( |
| 239 | + $t['test'], $t['input'], $t['result'], $t['options'], $t['config'] |
| 240 | + ); |
| 241 | + PHPUnit_Framework_Assert::assertTrue(true, $t['test']); |
| 242 | + } |
| 243 | + catch (PHPUnit_Framework_AssertionFailedError $e) { |
| 244 | + $result->addFailure($this, $e, PHPUnit_Util_Timer::stop()); |
| 245 | + } |
| 246 | + catch (Exception $e) { |
| 247 | + $result->addError($this, $e, PHPUnit_Util_Timer::stop()); |
| 248 | + } |
| 249 | + PHPUnit_Framework_Assert::assertTrue(true, $t['test']); |
| 250 | + |
| 251 | + $result->endTest($this, PHPUnit_Util_Timer::stop()); |
| 252 | + |
| 253 | + MediaWikiParserTestSuite::$parser->recorder->record($t['test'], $r); |
| 254 | + MediaWikiParserTestSuite::$iter->next(); |
| 255 | + $this->addToAssertionCount(PHPUnit_Framework_Assert::getCount()); |
| 256 | + |
| 257 | + return $result; |
194 | 258 | } |
195 | 259 | |
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; */ |
| 260 | +} |
201 | 261 | |
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']; */ |
| 262 | +class PTShell extends ParserTest { |
| 263 | + function showTesting( $desc ) { |
| 264 | + } |
210 | 265 | |
| 266 | + function showRunFile( $path ) { |
211 | 267 | } |
212 | 268 | |
| 269 | + function showSuccess( $desc ) { |
| 270 | + PHPUnit_Framework_Assert::assertTrue(true, $desc); |
| 271 | + return true; |
| 272 | + } |
213 | 273 | |
214 | | - function testParser() { |
215 | | - global $IP; |
| 274 | + function showFailure( $desc, $expected, $got ) { |
| 275 | + PHPUnit_Framework_Assert::assertEquals($expected, $got, $desc); |
| 276 | + } |
216 | 277 | |
217 | | - $this->parserTester->runTestsFromFiles( array( "$IP/maintenance/parserTests.txt" ) ); |
218 | | - } |
219 | 278 | } |
220 | 279 | |
| 280 | + |