Partial revert of r79154. hexmode asserts that these work, even though I keep getting...
authorX! <soxred93@users.mediawiki.org>
Wed, 29 Dec 2010 03:35:17 +0000 (03:35 +0000)
committerX! <soxred93@users.mediawiki.org>
Wed, 29 Dec 2010 03:35:17 +0000 (03:35 +0000)
tests/phpunit/includes/parser/MediaWikiParserTest.php
tests/phpunit/includes/parser/ParserHelpers.php

index fcc10a8..ce7f770 100644 (file)
@@ -3,62 +3,72 @@
 require_once( dirname( __FILE__ ) . '/ParserHelpers.php' );
 require_once( dirname(dirname(dirname( __FILE__ ))) . '/bootstrap.php' );
 
-/**
- * @group Parser
- * @group Destructive
- * @group Database
- */
 class MediaWikiParserTest extends MediaWikiTestCase {
        public $count;          // Number of tests in the suite.
+       public $backend;        // ParserTestSuiteBackend instance
        public $articles = array();     // Array of test articles defined by the tests
-       protected $pt;
-       
-       function setUp() {
-               global $wgContLang;
-               $wgContLang = Language::factory( 'en' );
-               
-               $this->pt = new PHPUnitParserTest;
-               $this->pt->setupDatabase();
-               
+
+       public function __construct() {
+               parent::__construct();
+               $this->backend = new ParserTestSuiteBackend;
+               $this->setName( 'Parser tests' );
        }
-       
-       function tearDown() {
-               if( is_object( $this->pt ) && $this->pt instanceof PHPUnitParserTest ) {
-                       $this->pt->teardownDatabase();
-                       $this->pt = null;
+
+       public static function suite() {
+               global $IP;
+
+               $tester = new self;
+               $tester->suite = new PHPUnit_Framework_TestSuite('Parser Tests');
+               
+               //Fixme: Use all the wgParserTestFiles (or whatever that global was...)
+               $iter = new TestFileIterator( "$IP/tests/parser/parserTests.txt", $tester );
+               $tester->count = 0;
+
+               foreach ( $iter as $test ) {
+                       $tester->suite->addTest( new ParserUnitTest( $tester, $test ), array( 'Parser', 'Destructive', 'Database', 'Broken' ) );
+                       $tester->count++;
                }
+
+               return $tester->suite;
        }
 
-       
-       public function testParserTests() {
-               //global $IP;
-               //$wgParserTestFiles = array( "$IP/tests/parser/testparserTests.txt" );
-               
-               global $wgParserTestFiles;
-               
-               foreach( $wgParserTestFiles as $file ) {
-                       
-                       $iter = new TestFileIterator( $file, $this->pt );
-                       
-                       try {
-                               foreach( $iter as $test ) {
-                                       $r = $this->pt->runTest( $test['test'], $test['input'],
-                                               $test['result'], $test['options'], $test['config']
-                                       );
-                                       
-                                       $this->assertTrue( $r, 'Parser test ' . $test['test'] );
-                                       
-                               }
-                       } 
-                       catch( DBQueryError $e ) {
-                               $this->assertTrue( false, 'Parser test ' . $test['test'] . ' (error: "' . $e->getMessage() . '")' );
-                               //This is annoying... it always stops on error and doesn't go to the next one.
-                               continue;
+       public function count() {
+               return $this->count;
+       }
+
+       public function toString() {
+               return "MediaWiki Parser Tests";
+       }
+
+       public function getBackend() {
+               return $this->backend;
+       }
+
+       public function getIterator() {
+               return $this->iterator;
+       }
+
+       public function publishTestArticles() {
+               if ( empty( $this->articles ) ) {
+                       return;
+               }
+
+               foreach ( $this->articles as $name => $text ) {
+                       $title = Title::newFromText( $name );
+
+                       if ( $title->getArticleID( Title::GAID_FOR_UPDATE ) == 0 ) {
+                               ParserTest::addArticle( $name, $text );
                        }
-                       
                }
-               
+               $this->articles = array();
        }
 
+       public function addArticle( $name, $text, $line ) {
+               $this->articles[$name] = $text;
+       }
+
+       public function showRunFile( $path ) {
+               /* Nothing shown when run from phpunit */
+       }
 }
 
index ad0bfd1..5b49480 100644 (file)
@@ -4,20 +4,19 @@ class PHPUnitParserTest extends ParserTest {
        function showTesting( $desc ) {
                global $additionalMWCLIArgs;
                if( $additionalMWCLIArgs['verbose'] ) parent::showTesting( $desc );
-               //var_dump($options);
                /* Do nothing since we don't want to show info during PHPUnit testing. */
        }
 
        public function showSuccess( $desc ) {
                global $additionalMWCLIArgs;
-               
+               PHPUnit_Framework_Assert::assertTrue( true, $desc );
                if( $additionalMWCLIArgs['verbose'] ) parent::showSuccess( $desc );
                return true;
        }
 
        public function showFailure( $desc, $expected, $got ) {
                global $additionalMWCLIArgs;
-               
+               PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
                if( $additionalMWCLIArgs['verbose'] ) parent::showFailure( $desc, $expected, $got );
                return false;
        }