r80688 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80687‎ | r80688 | r80689 >
Date:15:56, 21 January 2011
Author:daniel
Status:deferred
Tags:
Comment:
make DataTransclusionTest work with phpunit.php wrapper
Modified paths:
  • /trunk/extensions/DataTransclusion/tests/DataTransclusionTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DataTransclusion/tests/DataTransclusionTest.php
@@ -1,28 +1,30 @@
22 <?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 );
627 }
728
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 -
2729 class DataTransclusionTest extends PHPUnit_Framework_TestCase {
2830 protected static $templates = array(
2931 'Test' => "{{{source-name}}}:'''{{{id}}}'''|{{{name}}}|{{{extra}}}|{{{info}}}|[{{{url}}} link]|[{{{evil}}} click me]",
@@ -46,27 +48,15 @@
4749 }
4850
4951 function setUp() {
50 - global $wgTitle;
 52+ global $wgTitle, $wgParser;
5153
5254 $wgTitle = Title::newFromText( "Test" );
 55+
 56+ $wgParser->Options( new ParserOptions() );
 57+ $wgParser->clearState();
 58+ $wgParser->setTitle( $wgTitle );
5359 }
5460
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 -
7161 function testErrorMessage() {
7262 $m = DataTransclusionHandler::errorMessage( 'datatransclusion-test-wikitext', false );
7363 $this->assertEquals( $m, '<span class="error datatransclusion-test-wikitext">some <span class="test">html</span> and \'\'markup\'\'.</span>' );
@@ -257,7 +247,8 @@
258248 $text = 'xx {{#record:Test|FOO|id=3|extra=Hallo}} xx';
259249 $wgParser->parse( $text, $title, $options );
260250
261 - $html = $wgParser->getOutput()->getText();
 251+ $html = $wgParser->getOutput()->getText();
 252+ print "<<<$html>>>";
262253 $this->assertEquals( $html, '<p>xx FOO:<b>3</b>|foo|Hallo|&lt;test&gt;&amp;&#91;&#91;X&#93;&#93;&#39;|<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
263254 $templates = $wgParser->getOutput()->getTemplates();
264255 $this->assertTrue( isset( $templates[ NS_TEMPLATE ]['Test'] ) );
@@ -500,10 +491,25 @@
501492 }
502493 }
503494
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+}

Status & tagging log