Various fixes for PHPUnit tests:
authorPaul Copperman <pcopp@users.mediawiki.org>
Thu, 7 Apr 2011 14:54:38 +0000 (14:54 +0000)
committerPaul Copperman <pcopp@users.mediawiki.org>
Thu, 7 Apr 2011 14:54:38 +0000 (14:54 +0000)
* 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.

includes/Block.php
includes/Title.php
includes/api/ApiBlock.php
tests/phpunit/includes/ArticleTablesTest.php
tests/phpunit/includes/TitlePermissionTest.php
tests/phpunit/includes/api/ApiQueryTest.php
tests/phpunit/includes/api/ApiTestCaseUpload.php
tests/phpunit/includes/api/RandomImageGenerator.php

index 5c0bc0c..f1b3e7f 100644 (file)
@@ -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
index 08e3695..3e66902 100644 (file)
@@ -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 );
index 37e3a27..e0a3506 100644 (file)
@@ -90,6 +90,7 @@ class ApiBlock extends ApiBase {
                        'DisableUTEdit' => $params['allowusertalk'],
                        'AlreadyBlocked' => $params['reblock'],
                        'Watch' => $params['watchuser'],
+                       'Confirm' => true,
                );
 
                $retval = SpecialBlock::processForm( $data );
index 3db0b55..a35af50 100644 (file)
@@ -18,7 +18,10 @@ class ArticleTablesTest extends MediaWikiTestCase {
                $wgContLang = new StubContLang;
                $wgLang = new StubUserLang;
        }
-       
+
+       /**
+        * @group Broken
+        */
        function testbug14404() {
                global $wgUser, $wgContLang, $wgLanguageCode, $wgLang;
                
index 07c76e5..2b675d5 100644 (file)
@@ -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 ) );
 
index 9e85704..5c9ef93 100644 (file)
@@ -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]
                );
index a7fc9bd..7703a7e 100644 (file)
@@ -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() );
        }
index 6bb9d00..169d39d 100644 (file)
@@ -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] ) ) {