function setUp() {
$globalSet = array(
'wgLegacyEncoding' => false,
- 'wgUseLatin1' => false,
'wgCompressRevisions' => false,
'wgInputEncoding' => 'utf-8',
'wgOutputEncoding' => 'utf-8' );
<?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(
}
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() );
}
function testTime() {
$start = wfTime();
- $this->assertType( 'double', $start );
+ $this->assertType( 'float', $start );
$end = wfTime();
$this->assertTrue( $end > $start, "Time is running backwards!" );
}
.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 .
--- /dev/null
+<?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
+++ /dev/null
-<?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;
- }
-}
-
-?>
<?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() {
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;
$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" );
}
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" );
}
$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" );
}
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" );
}
<?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();