r22801 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22800‎ | r22801 | r22802 >
Date:18:37, 6 June 2007
Author:brion
Status:old
Tags:
Comment:
Update test cases to run
Modified paths:
  • /trunk/phase3/tests/ArticleTest.php (modified) (history)
  • /trunk/phase3/tests/GlobalTest.php (modified) (history)
  • /trunk/phase3/tests/Makefile (modified) (history)
  • /trunk/phase3/tests/MediaWiki_TestCase.php (added) (history)
  • /trunk/phase3/tests/RunTests.php (deleted) (history)
  • /trunk/phase3/tests/SearchEngineTest.php (modified) (history)
  • /trunk/phase3/tests/SearchMySQL4Test.php (modified) (history)

Diff [purge]

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 @@
22 <?php
33
 4+require_once 'MediaWiki_TestCase.php';
 5+
46 /** @todo document */
5 -class SearchEngine_TestCase extends PHPUnit_Framework_TestCase {
 7+class SearchEngineTest extends MediaWiki_TestCase {
68 var $db, $search;
79
810 function insertSearchData() {
@@ -65,8 +67,8 @@
6668
6769 function fetchIds( &$results ) {
6870 $matches = array();
69 - while( $row = $results->fetchObject() ) {
70 - $matches[] = intval( $row->page_id );
 71+ while( $row = $results->next() ) {
 72+ $matches[] = $row->getTitle()->getPrefixedText();
7173 }
7274 $results->free();
7375 # Search is not guaranteed to return results in a certain order;
@@ -80,7 +82,7 @@
8183 $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." );
8284 if( !is_null( $this->db ) ) {
8385 $this->assertEquals(
84 - array( 3 ),
 86+ array( 'Smithee' ),
8587 $this->fetchIds( $this->search->searchText( 'smithee' ) ),
8688 "Plain search failed" );
8789 }
@@ -91,7 +93,10 @@
9294 if( !is_null( $this->db ) ) {
9395 $this->search->setNamespaces( array( 0, 1, 4 ) );
9496 $this->assertEquals(
95 - array( 2, 3 ),
 97+ array(
 98+ 'Smithee',
 99+ 'Talk:Main Page',
 100+ ),
96101 $this->fetchIds( $this->search->searchText( 'smithee' ) ),
97102 "Power search failed" );
98103 }
@@ -101,7 +106,10 @@
102107 $this->assertFalse( is_null( $this->db ), "Can't find a database to test with." );
103108 if( !is_null( $this->db ) ) {
104109 $this->assertEquals(
105 - array( 3, 9 ),
 110+ array(
 111+ 'Alan Smithee',
 112+ 'Smithee',
 113+ ),
106114 $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
107115 "Title search failed" );
108116 }
@@ -112,7 +120,11 @@
113121 if( !is_null( $this->db ) ) {
114122 $this->search->setNamespaces( array( 0, 1, 4 ) );
115123 $this->assertEquals(
116 - array( 3, 4, 9 ),
 124+ array(
 125+ 'Alan Smithee',
 126+ 'Smithee',
 127+ 'Talk:Smithee',
 128+ ),
117129 $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
118130 "Title power search failed" );
119131 }
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
154 + native
Index: trunk/phase3/tests/GlobalTest.php
@@ -1,6 +1,21 @@
22 <?php
33
44 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+
520 function testRandom() {
621 # This could hypothetically fail, but it shouldn't ;)
722 $this->assertFalse(
@@ -14,17 +29,29 @@
1530 }
1631
1732 function testReadOnlyEmpty() {
 33+ global $wgReadOnly;
 34+ $wgReadOnly = null;
 35+
1836 $this->assertFalse( wfReadOnly() );
 37+ $this->assertFalse( wfReadOnly() );
1938 }
2039
2140 function testReadOnlySet() {
22 - $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" );
 41+ global $wgReadOnly, $wgReadOnlyFile;
 42+
 43+ $f = fopen( $wgReadOnlyFile, "wt" );
2344 fwrite( $f, 'Message' );
2445 fclose( $f );
 46+ $wgReadOnly = null;
 47+
2548 $this->assertTrue( wfReadOnly() );
 49+ $this->assertTrue( wfReadOnly() );
2650
27 - unlink( $GLOBALS['wgReadOnlyFile'] );
 51+ unlink( $wgReadOnlyFile );
 52+ $wgReadOnly = null;
 53+
2854 $this->assertFalse( wfReadOnly() );
 55+ $this->assertFalse( wfReadOnly() );
2956 }
3057
3158 function testQuotedPrintable() {
@@ -35,7 +62,7 @@
3663
3764 function testTime() {
3865 $start = wfTime();
39 - $this->assertType( 'double', $start );
 66+ $this->assertType( 'float', $start );
4067 $end = wfTime();
4168 $this->assertTrue( $end > $start, "Time is running backwards!" );
4269 }
Index: trunk/phase3/tests/SearchMySQL4Test.php
@@ -1,17 +1,16 @@
22 <?php
33 require_once( 'SearchEngineTest.php' );
44
5 -class SearchMySQL4Test extends SearchEngine_TestCase {
 5+class SearchMySQL4Test extends SearchEngineTest {
66 var $db;
77
8 - function SearchMySQL4Test( $name ) {
9 - $this->PHPUnit_TestCase( $name );
 8+ function __construct( $name ) {
 9+ parent::__construct( $name );
1010 }
1111
1212 function setUp() {
1313 $GLOBALS['wgContLang'] = new Language;
14 - $this->db =& buildTestDatabase(
15 - 'mysql4',
 14+ $this->db = $this->buildTestDatabase(
1615 array( 'page', 'revision', 'text', 'searchindex' ) );
1716 if( $this->db ) {
1817 $this->insertSearchData();
Index: trunk/phase3/tests/ArticleTest.php
@@ -6,7 +6,6 @@
77 function setUp() {
88 $globalSet = array(
99 'wgLegacyEncoding' => false,
10 - 'wgUseLatin1' => false,
1110 'wgCompressRevisions' => false,
1211 'wgInputEncoding' => 'utf-8',
1312 'wgOutputEncoding' => 'utf-8' );
Index: trunk/phase3/tests/Makefile
@@ -1,6 +1,10 @@
22 .PHONY: help test
33 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
59 install:
610 cvs -z9 -d:pserver:cvsread:@cvs.php.net:/repository/ co -P pear/PHPUnit
711 mv pear/PHPUnit .

Follow-up revisions

RevisionCommit summaryAuthorDate
r22811Merged revisions 22791-22810 via svnmerge from...david07:26, 7 June 2007

Status & tagging log