From a26353ec0ba9fc4969796d7dd5c721890d6c9c69 Mon Sep 17 00:00:00 2001 From: X! Date: Fri, 31 Dec 2010 21:40:26 +0000 Subject: [PATCH] -If $this->db does not exist, skip destroying the DB -Fix ApiTest errors due to DB rewrite --- tests/phpunit/MediaWikiTestCase.php | 4 ++++ tests/phpunit/includes/api/ApiSetup.php | 16 ++++++++-------- tests/phpunit/includes/api/ApiTest.php | 16 ++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 8f54280b12..8998e2c18e 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -132,6 +132,10 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { //Temporary tables seem to be broken ATM, delete anyway } + if( is_null( $this->db ) ) { + return; + } + if( $this->db->getType() == 'oracle' ) { $tables = $this->db->listTables( 'ut_', __METHOD__ ); } diff --git a/tests/phpunit/includes/api/ApiSetup.php b/tests/phpunit/includes/api/ApiSetup.php index 80ead6bb8d..aa5901ed2c 100644 --- a/tests/phpunit/includes/api/ApiSetup.php +++ b/tests/phpunit/includes/api/ApiSetup.php @@ -1,8 +1,8 @@ setupUser(); } protected function doApiRequest( $params, $data = null ) { @@ -31,13 +31,13 @@ abstract class ApiTestSetup extends MediaWikiTestCase { return $data; } - static function setupUser() { - if ( self::$user == null || self::$sysopUser == null ) { - self::$user = new UserWrapper( 'User for MediaWiki automated tests', User::randomPassword() ); - self::$sysopUser = new UserWrapper( 'Sysop for MediaWiki automated tests', User::randomPassword(), 'sysop' ); + function setupUser() { + if ( $this->user == null || $this->sysopUser == null ) { + $this->user = new UserWrapper( 'User for MediaWiki automated tests', User::randomPassword() ); + $this->sysopUser = new UserWrapper( 'Sysop for MediaWiki automated tests', User::randomPassword(), 'sysop' ); } - $GLOBALS['wgUser'] = self::$sysopUser->user; + $GLOBALS['wgUser'] = $this->sysopUser->user; } } diff --git a/tests/phpunit/includes/api/ApiTest.php b/tests/phpunit/includes/api/ApiTest.php index 29f9869d91..a7ae903532 100644 --- a/tests/phpunit/includes/api/ApiTest.php +++ b/tests/phpunit/includes/api/ApiTest.php @@ -79,7 +79,7 @@ class ApiTest extends ApiTestSetup { */ function testApiLoginNoName() { $data = $this->doApiRequest( array( 'action' => 'login', - 'lgname' => '', 'lgpassword' => self::$user->password, + 'lgname' => '', 'lgpassword' => $this->user->password, ) ); $this->assertEquals( 'NoName', $data[0]['login']['result'] ); } @@ -87,7 +87,7 @@ class ApiTest extends ApiTestSetup { function testApiLoginBadPass() { global $wgServer; - $user = self::$user; + $user = $this->user; if ( !isset( $wgServer ) ) { $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); @@ -130,7 +130,7 @@ class ApiTest extends ApiTestSetup { $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } - $user = self::$user; + $user = $this->user; $ret = $this->doApiRequest( array( "action" => "login", @@ -174,8 +174,8 @@ class ApiTest extends ApiTestSetup { $req = MWHttpRequest::factory( self::$apiUrl . "?action=login&format=xml", array( "method" => "POST", "postData" => array( - "lgname" => self::$user->userName, - "lgpassword" => self::$user->password ) ) ); + "lgname" => $this->user->userName, + "lgpassword" => $this->user->password ) ) ); $req->execute(); libxml_use_internal_errors( true ); @@ -190,8 +190,8 @@ class ApiTest extends ApiTestSetup { $req->setData( array( "lgtoken" => $token, - "lgname" => self::$user->userName, - "lgpassword" => self::$user->password ) ); + "lgname" => $this->user->userName, + "lgpassword" => $this->user->password ) ); $req->execute(); $cj = $req->getCookieJar(); @@ -199,7 +199,7 @@ class ApiTest extends ApiTestSetup { $this->assertNotEquals( false, $serverName ); $serializedCookie = $cj->serializeToHttpRequest( $wgScriptPath, $serverName ); $this->assertNotEquals( '', $serializedCookie ); - $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$user->userName . '; .*Token=/', $serializedCookie ); + $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . $this->user->userName . '; .*Token=/', $serializedCookie ); return $cj; } -- 2.20.1