From: Paul Copperman Date: Thu, 7 Apr 2011 14:54:38 +0000 (+0000) Subject: Various fixes for PHPUnit tests: X-Git-Tag: 1.31.0-rc.0~30980 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=f7e6dfb4a33b2fd4dabf613d69e1824e39772aa6;p=lhc%2Fweb%2Fwiklou.git Various fixes for PHPUnit tests: * Block.php: Set mExpiry to the value we store in the database, so that Block::equals() returns true. Fixes BlockTest::testInitializerFunctionsReturnCorrectBlock. * In Title::checkUserBlock(): Convert message parameters to plain strings to make strict comparisons work. Fixes TitlePermissionTest::testUserBlock(). * ApiBlock.php: Follow-Up r85166, add 'Confirm' parameter to data array. Fixes ApiBlockTest::testMakeNormalBlock(). * ApiQueryTest.php: Use $wgMetaNamespace instead of $wgSitename to account for customizations. * RandomImageGenerator.php: Use default value for constructor param to prevent fatals. * ApiTestCaseUpload.php: ** Fix undefined variable $fileName. ** Remove stray ini_set statements, they don't belong there. Especially ini_set( 'error_reporting', 1 ) will effectively disable all reporting, which makes errors hard to track. * ArticleTablesTest.php: Put testbug14404() in group Broken, as the fix for the bug has been reverted in r83868. --- diff --git a/includes/Block.php b/includes/Block.php index 5c0bc0ca1f..f1b3e7f821 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -444,6 +444,7 @@ class Block { if( !$db ){ $db = wfGetDB( DB_SLAVE ); } + $this->mExpiry = $db->encodeExpiry( $this->mExpiry ); $a = array( 'ipb_address' => (string)$this->target, @@ -456,7 +457,7 @@ class Block { 'ipb_anon_only' => !$this->isHardblock(), 'ipb_create_account' => $this->prevents( 'createaccount' ), 'ipb_enable_autoblock' => $this->isAutoblocking(), - 'ipb_expiry' => $db->encodeExpiry( $this->mExpiry ), + 'ipb_expiry' => $this->mExpiry, 'ipb_range_start' => $this->getRangeStart(), 'ipb_range_end' => $this->getRangeEnd(), 'ipb_deleted' => intval( $this->mHideName ), // typecast required for SQLite diff --git a/includes/Title.php b/includes/Title.php index 08e3695f25..3e6690212c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1563,12 +1563,12 @@ class Title { $blockExpiry = $user->mBlock->mExpiry; $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true ); if ( $blockExpiry == 'infinity' ) { - $blockExpiry = wfMessage( 'infiniteblock' ); + $blockExpiry = wfMessage( 'infiniteblock' )->text(); } else { $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true ); } - $intended = $user->mBlock->getTarget(); + $intended = strval( $user->mBlock->getTarget() ); $errors[] = array( ( $block->mAuto ? 'autoblockedtext' : 'blockedtext' ), $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp ); diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 37e3a27943..e0a35062f4 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -90,6 +90,7 @@ class ApiBlock extends ApiBase { 'DisableUTEdit' => $params['allowusertalk'], 'AlreadyBlocked' => $params['reblock'], 'Watch' => $params['watchuser'], + 'Confirm' => true, ); $retval = SpecialBlock::processForm( $data ); diff --git a/tests/phpunit/includes/ArticleTablesTest.php b/tests/phpunit/includes/ArticleTablesTest.php index 3db0b55109..a35af50e41 100644 --- a/tests/phpunit/includes/ArticleTablesTest.php +++ b/tests/phpunit/includes/ArticleTablesTest.php @@ -18,7 +18,10 @@ class ArticleTablesTest extends MediaWikiTestCase { $wgContLang = new StubContLang; $wgLang = new StubUserLang; } - + + /** + * @group Broken + */ function testbug14404() { global $wgUser, $wgContLang, $wgLanguageCode, $wgLang; diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 07c76e5114..2b675d58b7 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -625,7 +625,7 @@ class TitlePermissionTest extends MediaWikiTestCase { $this->user->mBlock->mTimestamp = 0; $this->assertEquals( array( array( 'autoblockedtext', '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', 0, 'infinite', '127.0.8.1', + 'Useruser', null, 'infinite', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ), $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); @@ -639,7 +639,7 @@ class TitlePermissionTest extends MediaWikiTestCase { $this->user->mBlock = new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 ); $this->assertEquals( array( array( 'blockedtext', '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1', + 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ), $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); diff --git a/tests/phpunit/includes/api/ApiQueryTest.php b/tests/phpunit/includes/api/ApiQueryTest.php index 9e85704886..5c9ef93b9b 100644 --- a/tests/phpunit/includes/api/ApiQueryTest.php +++ b/tests/phpunit/includes/api/ApiQueryTest.php @@ -14,7 +14,7 @@ class ApiQueryTest extends ApiTestSetup { function testTitlesGetNormalized() { - global $wgSitename; + global $wgMetaNamespace; $data = $this->doApiRequest( array( 'action' => 'query', @@ -27,7 +27,7 @@ class ApiQueryTest extends ApiTestSetup { $this->assertEquals( array( 'from' => 'Project:articleA', - 'to' => $wgSitename . ':ArticleA' + 'to' => $wgMetaNamespace . ':ArticleA' ), $data[0]['query']['normalized'][0] ); diff --git a/tests/phpunit/includes/api/ApiTestCaseUpload.php b/tests/phpunit/includes/api/ApiTestCaseUpload.php index a7fc9bd3d3..7703a7ef10 100644 --- a/tests/phpunit/includes/api/ApiTestCaseUpload.php +++ b/tests/phpunit/includes/api/ApiTestCaseUpload.php @@ -18,10 +18,6 @@ abstract class ApiTestCaseUpload extends ApiTestCase { $wgEnableAPI = true; wfSetupSession(); - ini_set( 'log_errors', 1 ); - ini_set( 'error_reporting', 1 ); - ini_set( 'display_errors', 1 ); - $this->clearFakeUploads(); } @@ -51,7 +47,7 @@ abstract class ApiTestCaseUpload extends ApiTestCase { $article->doDeleteArticle( "removing for test" ); // see if it now doesn't exist; reload - $title = Title::newFromText( $fileName, NS_FILE ); + $title = Title::newFromText( $title->getText(), NS_FILE ); } return ! ( $title && $title instanceof Title && $title->exists() ); } diff --git a/tests/phpunit/includes/api/RandomImageGenerator.php b/tests/phpunit/includes/api/RandomImageGenerator.php index 6bb9d00fee..169d39dda9 100644 --- a/tests/phpunit/includes/api/RandomImageGenerator.php +++ b/tests/phpunit/includes/api/RandomImageGenerator.php @@ -34,7 +34,7 @@ class RandomImageGenerator { private $circlesToDraw = 5; private $imageWriteMethod; - public function __construct( $options ) { + public function __construct( $options = array() ) { global $wgUseImageMagick, $wgImageMagickConvertCommand; foreach ( array( 'dictionaryFile', 'minWidth', 'minHeight', 'maxHeight', 'circlesToDraw' ) as $property ) { if ( isset( $options[$property] ) ) {