Index: trunk/phase3/tests/RunTests.php |
— | — | @@ -1,91 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -die( "This is broken, use run-test.php for now.\n" ); |
5 | | - |
6 | | -require_once( dirname( __FILE__ ) . '/../maintenance/commandLine.inc' ); |
7 | | -ini_set( 'include_path', get_include_path() . PATH_SEPARATOR . /*$_SERVER['PHP_PEAR_INSTALL_DIR']*/ 'C:\php\pear' ); |
8 | | -error_reporting( E_ALL ); |
9 | | -require_once( 'PHPUnit/Framework.php' ); |
10 | | - |
11 | | -$testOptions = array( |
12 | | - 'mysql4' => array( |
13 | | - 'server' => null, |
14 | | - 'user' => null, |
15 | | - 'password' => null, |
16 | | - 'database' => null ), |
17 | | - 'postgres' => array( |
18 | | - 'server' => null, |
19 | | - 'user' => null, |
20 | | - 'password' => null, |
21 | | - 'database' => null ), |
22 | | - ); |
23 | | - |
24 | | -$tests = array( |
25 | | - 'GlobalTest', |
26 | | - 'DatabaseTest', |
27 | | - 'SearchMySQL4Test', |
28 | | - 'ArticleTest', |
29 | | - 'SanitizerTest', |
30 | | - 'ImageTest' |
31 | | - ); |
32 | | - |
33 | | -if( count( $args ) ) { |
34 | | - // to override... |
35 | | - $tests = $args; |
36 | | -} |
37 | | - |
38 | | -foreach( $tests as $test ) { |
39 | | - require_once( $test . '.php' ); |
40 | | - $suite = new PHPUnit_Framework_TestSuite( $test ); |
41 | | - $result = PHPUnit::run( $suite ); |
42 | | - echo $result->toString(); |
43 | | -} |
44 | | - |
45 | | -/** |
46 | | - * @param string $serverType |
47 | | - * @param array $tables |
48 | | - */ |
49 | | -function &buildTestDatabase( $serverType, $tables ) { |
50 | | - global $testOptions, $wgDBprefix; |
51 | | - $wgDBprefix = 'parsertest'; |
52 | | - $db = new Database( |
53 | | - $testOptions[$serverType]['server'], |
54 | | - $testOptions[$serverType]['user'], |
55 | | - $testOptions[$serverType]['password'], |
56 | | - $testOptions[$serverType]['database'] ); |
57 | | - if( $db->isOpen() ) { |
58 | | - if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) { |
59 | | - # Database that supports CREATE TABLE ... LIKE |
60 | | - foreach ($tables as $tbl) { |
61 | | - $newTableName = $db->tableName( $tbl ); |
62 | | - #$tableName = $this->oldTableNames[$tbl]; |
63 | | - $tableName = $tbl; |
64 | | - $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)"); |
65 | | - } |
66 | | - } else { |
67 | | - # Hack for MySQL versions < 4.1, which don't support |
68 | | - # "CREATE TABLE ... LIKE". Note that |
69 | | - # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0" |
70 | | - # would not create the indexes we need.... |
71 | | - foreach ($tables as $tbl) { |
72 | | - $res = $db->query("SHOW CREATE TABLE $tbl"); |
73 | | - $row = $db->fetchRow($res); |
74 | | - $create = $row[1]; |
75 | | - $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `' |
76 | | - . $wgDBprefix . '\\1`', $create); |
77 | | - if ($create === $create_tmp) { |
78 | | - # Couldn't do replacement |
79 | | - wfDie( "could not create temporary table $tbl" ); |
80 | | - } |
81 | | - $db->query($create_tmp); |
82 | | - } |
83 | | - |
84 | | - } |
85 | | - return $db; |
86 | | - } else { |
87 | | - // Something amiss |
88 | | - return null; |
89 | | - } |
90 | | -} |
91 | | - |
92 | | -?> |
Index: trunk/phase3/tests/SearchEngineTest.php |
— | — | @@ -1,7 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +require_once 'MediaWiki_TestCase.php'; |
| 5 | + |
4 | 6 | /** @todo document */ |
5 | | -class SearchEngine_TestCase extends PHPUnit_Framework_TestCase { |
| 7 | +class SearchEngineTest extends MediaWiki_TestCase { |
6 | 8 | var $db, $search; |
7 | 9 | |
8 | 10 | function insertSearchData() { |
— | — | @@ -65,8 +67,8 @@ |
66 | 68 | |
67 | 69 | function fetchIds( &$results ) { |
68 | 70 | $matches = array(); |
69 | | - while( $row = $results->fetchObject() ) { |
70 | | - $matches[] = intval( $row->page_id ); |
| 71 | + while( $row = $results->next() ) { |
| 72 | + $matches[] = $row->getTitle()->getPrefixedText(); |
71 | 73 | } |
72 | 74 | $results->free(); |
73 | 75 | # Search is not guaranteed to return results in a certain order; |
— | — | @@ -80,7 +82,7 @@ |
81 | 83 | $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." ); |
82 | 84 | if( !is_null( $this->db ) ) { |
83 | 85 | $this->assertEquals( |
84 | | - array( 3 ), |
| 86 | + array( 'Smithee' ), |
85 | 87 | $this->fetchIds( $this->search->searchText( 'smithee' ) ), |
86 | 88 | "Plain search failed" ); |
87 | 89 | } |
— | — | @@ -91,7 +93,10 @@ |
92 | 94 | if( !is_null( $this->db ) ) { |
93 | 95 | $this->search->setNamespaces( array( 0, 1, 4 ) ); |
94 | 96 | $this->assertEquals( |
95 | | - array( 2, 3 ), |
| 97 | + array( |
| 98 | + 'Smithee', |
| 99 | + 'Talk:Main Page', |
| 100 | + ), |
96 | 101 | $this->fetchIds( $this->search->searchText( 'smithee' ) ), |
97 | 102 | "Power search failed" ); |
98 | 103 | } |
— | — | @@ -101,7 +106,10 @@ |
102 | 107 | $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." ); |
103 | 108 | if( !is_null( $this->db ) ) { |
104 | 109 | $this->assertEquals( |
105 | | - array( 3, 9 ), |
| 110 | + array( |
| 111 | + 'Alan Smithee', |
| 112 | + 'Smithee', |
| 113 | + ), |
106 | 114 | $this->fetchIds( $this->search->searchTitle( 'smithee' ) ), |
107 | 115 | "Title search failed" ); |
108 | 116 | } |
— | — | @@ -112,7 +120,11 @@ |
113 | 121 | if( !is_null( $this->db ) ) { |
114 | 122 | $this->search->setNamespaces( array( 0, 1, 4 ) ); |
115 | 123 | $this->assertEquals( |
116 | | - array( 3, 4, 9 ), |
| 124 | + array( |
| 125 | + 'Alan Smithee', |
| 126 | + 'Smithee', |
| 127 | + 'Talk:Smithee', |
| 128 | + ), |
117 | 129 | $this->fetchIds( $this->search->searchTitle( 'smithee' ) ), |
118 | 130 | "Title power search failed" ); |
119 | 131 | } |
Index: trunk/phase3/tests/MediaWiki_TestCase.php |
— | — | @@ -0,0 +1,52 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase { |
| 5 | + /** |
| 6 | + * @param string $serverType |
| 7 | + * @param array $tables |
| 8 | + */ |
| 9 | + protected function buildTestDatabase( $tables ) { |
| 10 | + global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname; |
| 11 | + $wgDBprefix = 'parsertest'; |
| 12 | + $db = new Database( |
| 13 | + $wgDBserver, |
| 14 | + $wgDBadminuser, |
| 15 | + $wgDBadminpassword, |
| 16 | + $wgDBname ); |
| 17 | + if( $db->isOpen() ) { |
| 18 | + if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) { |
| 19 | + # Database that supports CREATE TABLE ... LIKE |
| 20 | + foreach ($tables as $tbl) { |
| 21 | + $newTableName = $db->tableName( $tbl ); |
| 22 | + #$tableName = $this->oldTableNames[$tbl]; |
| 23 | + $tableName = $tbl; |
| 24 | + $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)"); |
| 25 | + } |
| 26 | + } else { |
| 27 | + # Hack for MySQL versions < 4.1, which don't support |
| 28 | + # "CREATE TABLE ... LIKE". Note that |
| 29 | + # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0" |
| 30 | + # would not create the indexes we need.... |
| 31 | + foreach ($tables as $tbl) { |
| 32 | + $res = $db->query("SHOW CREATE TABLE $tbl"); |
| 33 | + $row = $db->fetchRow($res); |
| 34 | + $create = $row[1]; |
| 35 | + $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `' |
| 36 | + . $wgDBprefix . '\\1`', $create); |
| 37 | + if ($create === $create_tmp) { |
| 38 | + # Couldn't do replacement |
| 39 | + wfDie( "could not create temporary table $tbl" ); |
| 40 | + } |
| 41 | + $db->query($create_tmp); |
| 42 | + } |
| 43 | + |
| 44 | + } |
| 45 | + return $db; |
| 46 | + } else { |
| 47 | + // Something amiss |
| 48 | + return null; |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +?> |
\ No newline at end of file |
Property changes on: trunk/phase3/tests/MediaWiki_TestCase.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 54 | + native |
Index: trunk/phase3/tests/GlobalTest.php |
— | — | @@ -1,6 +1,21 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class GlobalTest extends PHPUnit_Framework_TestCase { |
| 5 | + function setUp() { |
| 6 | + global $wgReadOnlyFile; |
| 7 | + $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile; |
| 8 | + $wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly"); |
| 9 | + unlink( $wgReadOnlyFile ); |
| 10 | + } |
| 11 | + |
| 12 | + function tearDown() { |
| 13 | + global $wgReadOnlyFile; |
| 14 | + if( file_exists( $wgReadOnlyFile ) ) { |
| 15 | + unlink( $wgReadOnlyFile ); |
| 16 | + } |
| 17 | + $wgReadOnlyFile = $this->originals['wgReadOnlyFile']; |
| 18 | + } |
| 19 | + |
5 | 20 | function testRandom() { |
6 | 21 | # This could hypothetically fail, but it shouldn't ;) |
7 | 22 | $this->assertFalse( |
— | — | @@ -14,17 +29,29 @@ |
15 | 30 | } |
16 | 31 | |
17 | 32 | function testReadOnlyEmpty() { |
| 33 | + global $wgReadOnly; |
| 34 | + $wgReadOnly = null; |
| 35 | + |
18 | 36 | $this->assertFalse( wfReadOnly() ); |
| 37 | + $this->assertFalse( wfReadOnly() ); |
19 | 38 | } |
20 | 39 | |
21 | 40 | function testReadOnlySet() { |
22 | | - $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" ); |
| 41 | + global $wgReadOnly, $wgReadOnlyFile; |
| 42 | + |
| 43 | + $f = fopen( $wgReadOnlyFile, "wt" ); |
23 | 44 | fwrite( $f, 'Message' ); |
24 | 45 | fclose( $f ); |
| 46 | + $wgReadOnly = null; |
| 47 | + |
25 | 48 | $this->assertTrue( wfReadOnly() ); |
| 49 | + $this->assertTrue( wfReadOnly() ); |
26 | 50 | |
27 | | - unlink( $GLOBALS['wgReadOnlyFile'] ); |
| 51 | + unlink( $wgReadOnlyFile ); |
| 52 | + $wgReadOnly = null; |
| 53 | + |
28 | 54 | $this->assertFalse( wfReadOnly() ); |
| 55 | + $this->assertFalse( wfReadOnly() ); |
29 | 56 | } |
30 | 57 | |
31 | 58 | function testQuotedPrintable() { |
— | — | @@ -35,7 +62,7 @@ |
36 | 63 | |
37 | 64 | function testTime() { |
38 | 65 | $start = wfTime(); |
39 | | - $this->assertType( 'double', $start ); |
| 66 | + $this->assertType( 'float', $start ); |
40 | 67 | $end = wfTime(); |
41 | 68 | $this->assertTrue( $end > $start, "Time is running backwards!" ); |
42 | 69 | } |
Index: trunk/phase3/tests/SearchMySQL4Test.php |
— | — | @@ -1,17 +1,16 @@ |
2 | 2 | <?php |
3 | 3 | require_once( 'SearchEngineTest.php' ); |
4 | 4 | |
5 | | -class SearchMySQL4Test extends SearchEngine_TestCase { |
| 5 | +class SearchMySQL4Test extends SearchEngineTest { |
6 | 6 | var $db; |
7 | 7 | |
8 | | - function SearchMySQL4Test( $name ) { |
9 | | - $this->PHPUnit_TestCase( $name ); |
| 8 | + function __construct( $name ) { |
| 9 | + parent::__construct( $name ); |
10 | 10 | } |
11 | 11 | |
12 | 12 | function setUp() { |
13 | 13 | $GLOBALS['wgContLang'] = new Language; |
14 | | - $this->db =& buildTestDatabase( |
15 | | - 'mysql4', |
| 14 | + $this->db = $this->buildTestDatabase( |
16 | 15 | array( 'page', 'revision', 'text', 'searchindex' ) ); |
17 | 16 | if( $this->db ) { |
18 | 17 | $this->insertSearchData(); |
Index: trunk/phase3/tests/ArticleTest.php |
— | — | @@ -6,7 +6,6 @@ |
7 | 7 | function setUp() { |
8 | 8 | $globalSet = array( |
9 | 9 | 'wgLegacyEncoding' => false, |
10 | | - 'wgUseLatin1' => false, |
11 | 10 | 'wgCompressRevisions' => false, |
12 | 11 | 'wgInputEncoding' => 'utf-8', |
13 | 12 | 'wgOutputEncoding' => 'utf-8' ); |
Index: trunk/phase3/tests/Makefile |
— | — | @@ -1,6 +1,10 @@ |
2 | 2 | .PHONY: help test |
3 | 3 | all test: |
4 | | - php RunTests.php |
| 4 | + php run-test.php ArticleTest.php |
| 5 | + php run-test.php GlobalTest.php |
| 6 | + php run-test.php DatabaseTest.php |
| 7 | + php run-test.php ImageFunctionsTest.php |
| 8 | + php run-test.php SearchMySQL4Test.php |
5 | 9 | install: |
6 | 10 | cvs -z9 -d:pserver:cvsread:@cvs.php.net:/repository/ co -P pear/PHPUnit |
7 | 11 | mv pear/PHPUnit . |