Index: trunk/extensions/DataTransclusion/tests/DataTransclusionTest.php |
— | — | @@ -1,28 +1,30 @@ |
2 | 2 | <?php |
3 | | -if ( isset( $GET_ ) ) { |
4 | | - echo( "This file cannot be run from the web.\n" ); |
5 | | - die( 1 ); |
| 3 | +if ( !defined('MW_PHPUNIT_TEST') ) { |
| 4 | + if ( isset( $GET_ ) ) { |
| 5 | + echo( "This file cannot be run from the web.\n" ); |
| 6 | + die( 1 ); |
| 7 | + } |
| 8 | + |
| 9 | + if ( getenv( 'MW_INSTALL_PATH' ) ) { |
| 10 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
| 11 | + } else { |
| 12 | + $dir = dirname( __FILE__ ); |
| 13 | + |
| 14 | + if ( file_exists( "$dir/../../LocalSettings.php" ) ) $IP = "$dir/../.."; |
| 15 | + else if ( file_exists( "$dir/../../../LocalSettings.php" ) ) $IP = "$dir/../../.."; |
| 16 | + else if ( file_exists( "$dir/../../phase3/LocalSettings.php" ) ) $IP = "$dir/../../phase3"; |
| 17 | + else if ( file_exists( "$dir/../../../phase3/LocalSettings.php" ) ) $IP = "$dir/../../../phase3"; |
| 18 | + else $IP = $dir; |
| 19 | + } |
| 20 | + |
| 21 | + require_once( "$IP/maintenance/commandLine.inc" ); |
| 22 | + |
| 23 | + // requires PHPUnit 3.4 |
| 24 | + require_once 'PHPUnit/Framework.php'; |
| 25 | + |
| 26 | + error_reporting( E_ALL ); |
6 | 27 | } |
7 | 28 | |
8 | | -if ( getenv( 'MW_INSTALL_PATH' ) ) { |
9 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
10 | | -} else { |
11 | | - $dir = dirname( __FILE__ ); |
12 | | - |
13 | | - if ( file_exists( "$dir/../../LocalSettings.php" ) ) $IP = "$dir/../.."; |
14 | | - else if ( file_exists( "$dir/../../../LocalSettings.php" ) ) $IP = "$dir/../../.."; |
15 | | - else if ( file_exists( "$dir/../../phase3/LocalSettings.php" ) ) $IP = "$dir/../../phase3"; |
16 | | - else if ( file_exists( "$dir/../../../phase3/LocalSettings.php" ) ) $IP = "$dir/../../../phase3"; |
17 | | - else $IP = $dir; |
18 | | -} |
19 | | - |
20 | | -require_once( "$IP/maintenance/commandLine.inc" ); |
21 | | - |
22 | | -// requires PHPUnit 3.4 |
23 | | -require_once 'PHPUnit/Framework.php'; |
24 | | - |
25 | | -error_reporting( E_ALL ); |
26 | | - |
27 | 29 | class DataTransclusionTest extends PHPUnit_Framework_TestCase { |
28 | 30 | protected static $templates = array( |
29 | 31 | 'Test' => "{{{source-name}}}:'''{{{id}}}'''|{{{name}}}|{{{extra}}}|{{{info}}}|[{{{url}}} link]|[{{{evil}}} click me]", |
— | — | @@ -46,27 +48,15 @@ |
47 | 49 | } |
48 | 50 | |
49 | 51 | function setUp() { |
50 | | - global $wgTitle; |
| 52 | + global $wgTitle, $wgParser; |
51 | 53 | |
52 | 54 | $wgTitle = Title::newFromText( "Test" ); |
| 55 | + |
| 56 | + $wgParser->Options( new ParserOptions() ); |
| 57 | + $wgParser->clearState(); |
| 58 | + $wgParser->setTitle( $wgTitle ); |
53 | 59 | } |
54 | 60 | |
55 | | - function runTest() { |
56 | | - $this->testErrorMessage(); |
57 | | - $this->testSanitizeValue(); |
58 | | - $this->testNormalizeRecord(); |
59 | | - $this->testBuildAssociativeArguments(); |
60 | | - $this->testGetDataSource(); |
61 | | - $this->testCachedFetchRecord(); |
62 | | - $this->testRender(); |
63 | | - $this->testHandleRecordTransclusion(); |
64 | | - $this->testHandleRecordFunction(); |
65 | | - $this->testHandleRecordTag(); |
66 | | - $this->testDBDataTransclusionSource(); |
67 | | - $this->testWebDataTransclusionSource(); |
68 | | - $this->testXmlDataTransclusionSource(); |
69 | | - } |
70 | | - |
71 | 61 | function testErrorMessage() { |
72 | 62 | $m = DataTransclusionHandler::errorMessage( 'datatransclusion-test-wikitext', false ); |
73 | 63 | $this->assertEquals( $m, '<span class="error datatransclusion-test-wikitext">some <span class="test">html</span> and \'\'markup\'\'.</span>' ); |
— | — | @@ -257,7 +247,8 @@ |
258 | 248 | $text = 'xx {{#record:Test|FOO|id=3|extra=Hallo}} xx'; |
259 | 249 | $wgParser->parse( $text, $title, $options ); |
260 | 250 | |
261 | | - $html = $wgParser->getOutput()->getText(); |
| 251 | + $html = $wgParser->getOutput()->getText(); |
| 252 | + print "<<<$html>>>"; |
262 | 253 | $this->assertEquals( $html, '<p>xx FOO:<b>3</b>|foo|Hallo|<test>&[[X]]'|<a href="http://test.org/" class="external text" rel="nofollow">link</a>|[javascript:alert("evil") click me] xx'."\n".'</p>' ); // XXX: should be more lenient wrt whitespace |
263 | 254 | $templates = $wgParser->getOutput()->getTemplates(); |
264 | 255 | $this->assertTrue( isset( $templates[ NS_TEMPLATE ]['Test'] ) ); |
— | — | @@ -500,10 +491,25 @@ |
501 | 492 | } |
502 | 493 | } |
503 | 494 | |
504 | | -$wgShowExceptionDetails = true; |
505 | | - |
506 | | -$t = new DataTransclusionTest(); |
507 | | -$t->setUp(); |
508 | | -$t->runTest(); |
509 | | - |
510 | | -echo "OK.\n"; |
| 495 | +if ( !defined('MW_PHPUNIT_TEST') ) { |
| 496 | + $wgShowExceptionDetails = true; |
| 497 | + |
| 498 | + $t = new DataTransclusionTest(); |
| 499 | + $t->setUp(); |
| 500 | + |
| 501 | + $t->testErrorMessage(); |
| 502 | + $t->testSanitizeValue(); |
| 503 | + $t->testNormalizeRecord(); |
| 504 | + $t->testBuildAssociativeArguments(); |
| 505 | + $t->testGetDataSource(); |
| 506 | + $t->testCachedFetchRecord(); |
| 507 | + $t->testRender(); |
| 508 | + $t->testHandleRecordTransclusion(); |
| 509 | + $t->testHandleRecordFunction(); |
| 510 | + $t->testHandleRecordTag(); |
| 511 | + $t->testDBDataTransclusionSource(); |
| 512 | + $t->testWebDataTransclusionSource(); |
| 513 | + $t->testXmlDataTransclusionSource(); |
| 514 | + |
| 515 | + echo "OK.\n"; |
| 516 | +} |