Index: trunk/phase3/maintenance/tests/MediaWiki_TestCase.php |
— | — | @@ -1,53 +0,0 @@ |
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 | | - $this->markTestIncomplete("This test requires DB admin user credentials."); |
12 | | - $wgDBprefix = 'parsertest_'; |
13 | | - |
14 | | - $db = new DatabaseMysql( |
15 | | - $wgDBserver, |
16 | | - $wgDBadminuser, |
17 | | - $wgDBadminpassword, |
18 | | - $wgDBname ); |
19 | | - if( $db->isOpen() ) { |
20 | | - if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) { |
21 | | - # Database that supports CREATE TABLE ... LIKE |
22 | | - foreach ($tables as $tbl) { |
23 | | - $newTableName = $db->tableName( $tbl ); |
24 | | - #$tableName = $this->oldTableNames[$tbl]; |
25 | | - $tableName = $tbl; |
26 | | - $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)"); |
27 | | - } |
28 | | - } else { |
29 | | - # Hack for MySQL versions < 4.1, which don't support |
30 | | - # "CREATE TABLE ... LIKE". Note that |
31 | | - # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0" |
32 | | - # would not create the indexes we need.... |
33 | | - foreach ($tables as $tbl) { |
34 | | - $res = $db->query("SHOW CREATE TABLE $tbl"); |
35 | | - $row = $db->fetchRow($res); |
36 | | - $create = $row[1]; |
37 | | - $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `' |
38 | | - . $wgDBprefix . '\\1`', $create); |
39 | | - if ($create === $create_tmp) { |
40 | | - # Couldn't do replacement |
41 | | - wfDie( "could not create temporary table $tbl" ); |
42 | | - } |
43 | | - $db->query($create_tmp); |
44 | | - } |
45 | | - |
46 | | - } |
47 | | - return $db; |
48 | | - } else { |
49 | | - // Something amiss |
50 | | - return null; |
51 | | - } |
52 | | - } |
53 | | -} |
54 | | - |
Index: trunk/phase3/maintenance/tests/MediaWikiAPI_TestCase.php |
— | — | @@ -1,42 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -abstract class MediaWikiAPI_TestCase extends PHPUnit_Framework_TestCase { |
5 | | - protected static $userName; |
6 | | - protected static $passWord; |
7 | | - protected static $user; |
8 | | - protected static $apiUrl; |
9 | | - |
10 | | - function setup() { |
11 | | - global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath, |
12 | | - $wgScriptExtension, $wgMemc; |
13 | | - |
14 | | - if($wgServerName == "localhost" || $wgServer == "http://localhost") { |
15 | | - $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
16 | | - 'be set in LocalSettings.php'); |
17 | | - } |
18 | | - self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension; |
19 | | - |
20 | | - $wgMemc = new FakeMemCachedClient; |
21 | | - $wgContLang = Language::factory( 'en' ); |
22 | | - $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' ); |
23 | | - self::setupUser(); |
24 | | - } |
25 | | - |
26 | | - static function setupUser() { |
27 | | - if ( self::$user == NULL ) { |
28 | | - self::$userName = "Useruser"; |
29 | | - self::$passWord = User::randomPassword(); |
30 | | - |
31 | | - self::$user = User::newFromName(self::$userName); |
32 | | - if ( !self::$user->getID() ) { |
33 | | - self::$user = User::createNew(self::$userName, array( |
34 | | - "password" => self::$passWord, |
35 | | - "email" => "test@example.com", |
36 | | - "real_name" => "Test User")); |
37 | | - } else { |
38 | | - self::$user->setPassword(self::$passWord); |
39 | | - } |
40 | | - self::$user->saveSettings(); |
41 | | - } |
42 | | - } |
43 | | -} |
Index: trunk/phase3/maintenance/tests/SearchEngineTest.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once( 'MediaWiki_TestCase.php' ); |
| 4 | +require_once( 'MediaWiki_Setup.php' ); |
5 | 5 | |
6 | 6 | /** @todo document |
7 | 7 | */ |
8 | 8 | |
9 | | -class SearchEngineTest extends MediaWiki_TestCase { |
| 9 | +class SearchEngineTest extends MediaWiki_Setup { |
10 | 10 | var $db, $search; |
11 | 11 | |
12 | 12 | function insertSearchData() { |
Index: trunk/phase3/maintenance/tests/MediaWikiAPITest.php |
— | — | @@ -1,8 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once( "MediaWikiAPI_TestCase.php" ); |
| 4 | +require_once( "MediaWikiAPI_Setup.php" ); |
5 | 5 | |
6 | | -class MediaWikiAPITest extends MediaWikiAPI_TestCase { |
| 6 | +class MediaWikiAPITest extends MediaWikiAPI_Setup { |
7 | 7 | |
8 | 8 | function setup() { |
9 | 9 | parent::setup(); |
Index: trunk/phase3/maintenance/tests/MediaWikiAPI_Setup.php |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class MediaWikiAPI_Setup extends PHPUnit_Framework_TestCase { |
| 5 | + protected static $userName; |
| 6 | + protected static $passWord; |
| 7 | + protected static $user; |
| 8 | + protected static $apiUrl; |
| 9 | + |
| 10 | + function setup() { |
| 11 | + global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath, |
| 12 | + $wgScriptExtension, $wgMemc; |
| 13 | + |
| 14 | + if($wgServerName == "localhost" || $wgServer == "http://localhost") { |
| 15 | + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
| 16 | + 'be set in LocalSettings.php'); |
| 17 | + } |
| 18 | + self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension; |
| 19 | + |
| 20 | + $wgMemc = new FakeMemCachedClient; |
| 21 | + $wgContLang = Language::factory( 'en' ); |
| 22 | + $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' ); |
| 23 | + self::setupUser(); |
| 24 | + } |
| 25 | + |
| 26 | + static function setupUser() { |
| 27 | + if ( self::$user == NULL ) { |
| 28 | + self::$userName = "Useruser"; |
| 29 | + self::$passWord = User::randomPassword(); |
| 30 | + |
| 31 | + self::$user = User::newFromName(self::$userName); |
| 32 | + if ( !self::$user->getID() ) { |
| 33 | + self::$user = User::createNew(self::$userName, array( |
| 34 | + "password" => self::$passWord, |
| 35 | + "email" => "test@example.com", |
| 36 | + "real_name" => "Test User")); |
| 37 | + } else { |
| 38 | + self::$user->setPassword(self::$passWord); |
| 39 | + } |
| 40 | + self::$user->saveSettings(); |
| 41 | + } |
| 42 | + } |
| 43 | +} |
Property changes on: trunk/phase3/maintenance/tests/MediaWikiAPI_Setup.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 44 | + native |
Name: svn:eol-syle |
2 | 45 | + native |
Index: trunk/phase3/maintenance/tests/MediaWiki_Setup.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class MediaWiki_Setup 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 | + $this->markTestIncomplete("This test requires DB admin user credentials."); |
| 12 | + $wgDBprefix = 'parsertest_'; |
| 13 | + |
| 14 | + $db = new DatabaseMysql( |
| 15 | + $wgDBserver, |
| 16 | + $wgDBadminuser, |
| 17 | + $wgDBadminpassword, |
| 18 | + $wgDBname ); |
| 19 | + if( $db->isOpen() ) { |
| 20 | + if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) { |
| 21 | + # Database that supports CREATE TABLE ... LIKE |
| 22 | + foreach ($tables as $tbl) { |
| 23 | + $newTableName = $db->tableName( $tbl ); |
| 24 | + #$tableName = $this->oldTableNames[$tbl]; |
| 25 | + $tableName = $tbl; |
| 26 | + $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)"); |
| 27 | + } |
| 28 | + } else { |
| 29 | + # Hack for MySQL versions < 4.1, which don't support |
| 30 | + # "CREATE TABLE ... LIKE". Note that |
| 31 | + # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0" |
| 32 | + # would not create the indexes we need.... |
| 33 | + foreach ($tables as $tbl) { |
| 34 | + $res = $db->query("SHOW CREATE TABLE $tbl"); |
| 35 | + $row = $db->fetchRow($res); |
| 36 | + $create = $row[1]; |
| 37 | + $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `' |
| 38 | + . $wgDBprefix . '\\1`', $create); |
| 39 | + if ($create === $create_tmp) { |
| 40 | + # Couldn't do replacement |
| 41 | + wfDie( "could not create temporary table $tbl" ); |
| 42 | + } |
| 43 | + $db->query($create_tmp); |
| 44 | + } |
| 45 | + |
| 46 | + } |
| 47 | + return $db; |
| 48 | + } else { |
| 49 | + // Something amiss |
| 50 | + return null; |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | + |
Property changes on: trunk/phase3/maintenance/tests/MediaWiki_Setup.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 55 | + native |
Index: trunk/phase3/maintenance/tests/Makefile |
— | — | @@ -1,11 +1,17 @@ |
2 | 2 | .PHONY: help test |
3 | 3 | all test: |
4 | 4 | phpunit |
| 5 | + |
| 6 | +tap: |
| 7 | + prove -e 'phpunit --tap' *Test*.php |
| 8 | + |
5 | 9 | install: |
6 | 10 | pear channel-discover pear.phpunit.de |
7 | 11 | pear install phpunit/PHPUnit |
| 12 | + |
8 | 13 | help: |
9 | 14 | # Options: |
10 | 15 | # test (default) Run the unit tests |
| 16 | + # tap Run the tests individually through Test::Harness's prove(1) |
11 | 17 | # install Install PHPUnit from phpunit.de |
12 | 18 | # help You're looking at it! |