From: Brion Vibber Date: Wed, 6 Jun 2007 18:37:35 +0000 (+0000) Subject: Update test cases to run X-Git-Tag: 1.31.0-rc.0~52636 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/supprimer.php?a=commitdiff_plain;h=1bf3f2493e4bd494f523e67adb0e52c1b1ed582d;p=lhc%2Fweb%2Fwiklou.git Update test cases to run --- diff --git a/tests/ArticleTest.php b/tests/ArticleTest.php index 3276fc7a1d..425c5f2210 100644 --- a/tests/ArticleTest.php +++ b/tests/ArticleTest.php @@ -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' ); diff --git a/tests/GlobalTest.php b/tests/GlobalTest.php index e15556e0da..6aef6e483c 100644 --- a/tests/GlobalTest.php +++ b/tests/GlobalTest.php @@ -1,6 +1,21 @@ 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!" ); } diff --git a/tests/Makefile b/tests/Makefile index 0a649927ed..25ccda3523 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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 index 0000000000..2ba712deed --- /dev/null +++ b/tests/MediaWiki_TestCase.php @@ -0,0 +1,52 @@ +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 index aac1eb3e67..0000000000 --- a/tests/RunTests.php +++ /dev/null @@ -1,91 +0,0 @@ - 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; - } -} - -?> diff --git a/tests/SearchEngineTest.php b/tests/SearchEngineTest.php index 1494990b8f..9bc623ecbc 100644 --- a/tests/SearchEngineTest.php +++ b/tests/SearchEngineTest.php @@ -1,7 +1,9 @@ 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" ); } diff --git a/tests/SearchMySQL4Test.php b/tests/SearchMySQL4Test.php index 4f02f6423e..970cf685f2 100644 --- a/tests/SearchMySQL4Test.php +++ b/tests/SearchMySQL4Test.php @@ -1,17 +1,16 @@ 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();