Update test cases to run
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 6 Jun 2007 18:37:35 +0000 (18:37 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 6 Jun 2007 18:37:35 +0000 (18:37 +0000)
tests/ArticleTest.php
tests/GlobalTest.php
tests/Makefile
tests/MediaWiki_TestCase.php [new file with mode: 0644]
tests/RunTests.php [deleted file]
tests/SearchEngineTest.php
tests/SearchMySQL4Test.php

index 3276fc7..425c5f2 100644 (file)
@@ -6,7 +6,6 @@ class ArticleTest extends PHPUnit_Framework_TestCase {
        function setUp() {
                $globalSet = array(
                        'wgLegacyEncoding' => false,
-                       'wgUseLatin1' => false,
                        'wgCompressRevisions' => false,
                        'wgInputEncoding' => 'utf-8',
                        'wgOutputEncoding' => 'utf-8' );
index e15556e..6aef6e4 100644 (file)
@@ -1,6 +1,21 @@
 <?php
 
 class GlobalTest extends PHPUnit_Framework_TestCase {
+       function setUp() {
+               global $wgReadOnlyFile;
+               $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile;
+               $wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly");
+               unlink( $wgReadOnlyFile );
+       }
+       
+       function tearDown() {
+               global $wgReadOnlyFile;
+               if( file_exists( $wgReadOnlyFile ) ) {
+                       unlink( $wgReadOnlyFile );
+               }
+               $wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
+       }
+       
        function testRandom() {
                # This could hypothetically fail, but it shouldn't ;)
                $this->assertFalse(
@@ -14,16 +29,28 @@ class GlobalTest extends PHPUnit_Framework_TestCase {
        }
 
        function testReadOnlyEmpty() {
+               global $wgReadOnly;
+               $wgReadOnly = null;
+               
+               $this->assertFalse( wfReadOnly() );
                $this->assertFalse( wfReadOnly() );
        }
 
        function testReadOnlySet() {
-               $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" );
+               global $wgReadOnly, $wgReadOnlyFile;
+               
+               $f = fopen( $wgReadOnlyFile, "wt" );
                fwrite( $f, 'Message' );
                fclose( $f );
+               $wgReadOnly = null;
+               
+               $this->assertTrue( wfReadOnly() );
                $this->assertTrue( wfReadOnly() );
 
-               unlink( $GLOBALS['wgReadOnlyFile'] );
+               unlink( $wgReadOnlyFile );
+               $wgReadOnly = null;
+               
+               $this->assertFalse( wfReadOnly() );
                $this->assertFalse( wfReadOnly() );
        }
 
@@ -35,7 +62,7 @@ class GlobalTest extends PHPUnit_Framework_TestCase {
 
        function testTime() {
                $start = wfTime();
-               $this->assertType( 'double', $start );
+               $this->assertType( 'float', $start );
                $end = wfTime();
                $this->assertTrue( $end > $start, "Time is running backwards!" );
        }
index 0a64992..25ccda3 100644 (file)
@@ -1,6 +1,10 @@
 .PHONY: help test
 all test:
-       php RunTests.php
+       php run-test.php ArticleTest.php
+       php run-test.php GlobalTest.php
+       php run-test.php DatabaseTest.php
+       php run-test.php ImageFunctionsTest.php
+       php run-test.php SearchMySQL4Test.php
 install:
        cvs -z9 -d:pserver:cvsread:@cvs.php.net:/repository/ co -P pear/PHPUnit
        mv pear/PHPUnit .
diff --git a/tests/MediaWiki_TestCase.php b/tests/MediaWiki_TestCase.php
new file mode 100644 (file)
index 0000000..2ba712d
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase {
+       /**
+        * @param string $serverType
+        * @param array $tables
+        */
+       protected function buildTestDatabase( $tables ) {
+               global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
+               $wgDBprefix = 'parsertest';
+               $db = new Database(
+                       $wgDBserver,
+                       $wgDBadminuser,
+                       $wgDBadminpassword,
+                       $wgDBname );
+               if( $db->isOpen() ) {
+                       if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
+                               # Database that supports CREATE TABLE ... LIKE
+                               foreach ($tables as $tbl) {
+                                       $newTableName = $db->tableName( $tbl );
+                                       #$tableName = $this->oldTableNames[$tbl];
+                                       $tableName = $tbl;
+                                       $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
+                               }
+                       } else {
+                               # Hack for MySQL versions < 4.1, which don't support
+                               # "CREATE TABLE ... LIKE". Note that
+                               # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
+                               # would not create the indexes we need....
+                               foreach ($tables as $tbl) {
+                                       $res = $db->query("SHOW CREATE TABLE $tbl");
+                                       $row = $db->fetchRow($res);
+                                       $create = $row[1];
+                                       $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
+                                               . $wgDBprefix . '\\1`', $create);
+                                       if ($create === $create_tmp) {
+                                               # Couldn't do replacement
+                                               wfDie( "could not create temporary table $tbl" );
+                                       }
+                                       $db->query($create_tmp);
+                               }
+
+                       }
+                       return $db;
+               } else {
+                       // Something amiss
+                       return null;
+               }
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/tests/RunTests.php b/tests/RunTests.php
deleted file mode 100644 (file)
index aac1eb3..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-
-die( "This is broken, use run-test.php for now.\n" );
-
-require_once( dirname( __FILE__ ) . '/../maintenance/commandLine.inc' );
-ini_set( 'include_path', get_include_path() . PATH_SEPARATOR . /*$_SERVER['PHP_PEAR_INSTALL_DIR']*/ 'C:\php\pear' );
-error_reporting( E_ALL );
-require_once( 'PHPUnit/Framework.php' );
-
-$testOptions = array(
-       'mysql4' => array(
-               'server' => null,
-               'user' => null,
-               'password' => null,
-               'database' => null ),
-       'postgres' => array(
-               'server' => null,
-               'user' => null,
-               'password' => null,
-               'database' => null ),
-       );
-
-$tests = array(
-       'GlobalTest',
-       'DatabaseTest',
-       'SearchMySQL4Test',
-       'ArticleTest',
-       'SanitizerTest',
-       'ImageTest'
-       );
-
-if( count( $args ) ) {
-       // to override...
-       $tests = $args;
-}
-
-foreach( $tests as $test ) {
-       require_once( $test . '.php' );
-       $suite = new PHPUnit_Framework_TestSuite( $test );
-       $result = PHPUnit::run( $suite );
-       echo $result->toString();
-}
-
-/**
- * @param string $serverType
- * @param array $tables
- */
-function &buildTestDatabase( $serverType, $tables ) {
-       global $testOptions, $wgDBprefix;
-       $wgDBprefix = 'parsertest';
-       $db = new Database(
-               $testOptions[$serverType]['server'],
-               $testOptions[$serverType]['user'],
-               $testOptions[$serverType]['password'],
-               $testOptions[$serverType]['database'] );
-       if( $db->isOpen() ) {
-               if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
-                       # Database that supports CREATE TABLE ... LIKE
-                       foreach ($tables as $tbl) {
-                               $newTableName = $db->tableName( $tbl );
-                               #$tableName = $this->oldTableNames[$tbl];
-                               $tableName = $tbl;
-                               $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
-                       }
-               } else {
-                       # Hack for MySQL versions < 4.1, which don't support
-                       # "CREATE TABLE ... LIKE". Note that
-                       # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
-                       # would not create the indexes we need....
-                       foreach ($tables as $tbl) {
-                               $res = $db->query("SHOW CREATE TABLE $tbl");
-                               $row = $db->fetchRow($res);
-                               $create = $row[1];
-                               $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
-                                       . $wgDBprefix . '\\1`', $create);
-                               if ($create === $create_tmp) {
-                                       # Couldn't do replacement
-                                       wfDie( "could not create temporary table $tbl" );
-                               }
-                               $db->query($create_tmp);
-                       }
-
-               }
-               return $db;
-       } else {
-               // Something amiss
-               return null;
-       }
-}
-
-?>
index 1494990..9bc623e 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 
+require_once 'MediaWiki_TestCase.php';
+
 /** @todo document */
-class SearchEngine_TestCase extends PHPUnit_Framework_TestCase {
+class SearchEngineTest extends MediaWiki_TestCase {
        var $db, $search;
 
        function insertSearchData() {
@@ -65,8 +67,8 @@ END
 
        function fetchIds( &$results ) {
                $matches = array();
-               while( $row = $results->fetchObject() ) {
-                       $matches[] = intval( $row->page_id );
+               while( $row = $results->next() ) {
+                       $matches[] = $row->getTitle()->getPrefixedText();
                }
                $results->free();
                # Search is not guaranteed to return results in a certain order;
@@ -80,7 +82,7 @@ END
                $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." );
                if( !is_null( $this->db ) ) {
                        $this->assertEquals(
-                               array( 3 ),
+                               array( 'Smithee' ),
                                $this->fetchIds( $this->search->searchText( 'smithee' ) ),
                                "Plain search failed" );
                }
@@ -91,7 +93,10 @@ END
                if( !is_null( $this->db ) ) {
                        $this->search->setNamespaces( array( 0, 1, 4 ) );
                        $this->assertEquals(
-                               array( 2, 3 ),
+                               array(
+                                       'Smithee',
+                                       'Talk:Main Page',
+                               ),
                                $this->fetchIds( $this->search->searchText( 'smithee' ) ),
                                "Power search failed" );
                }
@@ -101,7 +106,10 @@ END
                $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." );
                if( !is_null( $this->db ) ) {
                        $this->assertEquals(
-                               array( 3, 9 ),
+                               array(
+                                       'Alan Smithee',
+                                       'Smithee',
+                               ),
                                $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
                                "Title search failed" );
                }
@@ -112,7 +120,11 @@ END
                if( !is_null( $this->db ) ) {
                        $this->search->setNamespaces( array( 0, 1, 4 ) );
                        $this->assertEquals(
-                               array( 3, 4, 9 ),
+                               array(
+                                       'Alan Smithee',
+                                       'Smithee',
+                                       'Talk:Smithee',
+                               ),
                                $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
                                "Title power search failed" );
                }
index 4f02f64..970cf68 100644 (file)
@@ -1,17 +1,16 @@
 <?php
 require_once( 'SearchEngineTest.php' );
 
-class SearchMySQL4Test extends SearchEngine_TestCase {
+class SearchMySQL4Test extends SearchEngineTest {
        var $db;
 
-       function SearchMySQL4Test( $name ) {
-               $this->PHPUnit_TestCase( $name );
+       function __construct( $name ) {
+               parent::__construct( $name );
        }
 
        function setUp() {
                $GLOBALS['wgContLang'] = new Language;
-               $this->db =& buildTestDatabase(
-                       'mysql4',
+               $this->db = $this->buildTestDatabase(
                        array( 'page', 'revision', 'text', 'searchindex' ) );
                if( $this->db ) {
                        $this->insertSearchData();