r89356 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89355‎ | r89356 | r89357 >
Date:19:32, 2 June 2011
Author:mah
Status:ok
Tags:
Comment:
w/s changes.
Modified paths:
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/search/SearchMySQL.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlock.php (modified) (history)
  • /trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php (modified) (history)
  • /trunk/phase3/tests/phpunit/MediaWikiTestCase.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php
@@ -18,7 +18,7 @@
1919 */
2020 const DB_PREFIX = 'unittest_';
2121 const ORA_DB_PREFIX = 'ut_';
22 -
 22+
2323 protected $supportedDBs = array(
2424 'mysql',
2525 'sqlite',
@@ -31,7 +31,7 @@
3232 $this->backupGlobals = false;
3333 $this->backupStaticAttributes = false;
3434 }
35 -
 35+
3636 function run( PHPUnit_Framework_TestResult $result = NULL ) {
3737 /* Some functions require some kind of caching, and will end up using the db,
3838 * which we can't allow, as that would open a new connection for mysql.
@@ -40,11 +40,11 @@
4141 ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
4242
4343 if( $this->needsDB() ) {
44 -
 44+
4545 global $wgDBprefix;
46 -
 46+
4747 $this->db = wfGetDB( DB_MASTER );
48 -
 48+
4949 $this->checkDbIsSupported();
5050
5151 $this->oldTablePrefix = $wgDBprefix;
@@ -56,7 +56,7 @@
5757
5858 $this->addCoreDBData();
5959 $this->addDBData();
60 -
 60+
6161 parent::run( $result );
6262
6363 $this->resetDB();
@@ -68,7 +68,7 @@
6969 function dbPrefix() {
7070 return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
7171 }
72 -
 72+
7373 function needsDB() {
7474 $rc = new ReflectionClass( $this );
7575 return strpos( $rc->getDocComment(), '@group Database' ) !== false;
@@ -79,14 +79,14 @@
8080 * implement this method and do so
8181 */
8282 function addDBData() {}
83 -
 83+
8484 private function addCoreDBData() {
8585
8686 User::resetIdByNameCache();
8787
8888 //Make sysop user
8989 $user = User::newFromName( 'UTSysop' );
90 -
 90+
9191 if ( $user->idForName() == 0 ) {
9292 $user->addToDatabase();
9393 $user->setPassword( 'UTSysopPassword' );
@@ -96,7 +96,7 @@
9797 $user->saveSettings();
9898 }
9999
100 -
 100+
101101 //Make 1 page with 1 revision
102102 $article = new Article( Title::newFromText( 'UTPage' ) );
103103 $article->doEdit( 'UTContent',
@@ -105,7 +105,7 @@
106106 false,
107107 User::newFromName( 'UTSysop' ) );
108108 }
109 -
 109+
110110 private function initDB() {
111111 global $wgDBprefix;
112112 if ( $wgDBprefix === $this->dbPrefix() ) {
@@ -182,7 +182,7 @@
183183 private function assertEmpty2( $value, $msg ) {
184184 return $this->assertTrue( $value == '', $msg );
185185 }
186 -
 186+
187187 static private function unprefixTable( $tableName ) {
188188 global $wgDBprefix;
189189 return substr( $tableName, strlen( $wgDBprefix ) );
@@ -211,25 +211,25 @@
212212 }
213213 return $tables;
214214 }
215 -
 215+
216216 protected function checkDbIsSupported() {
217217 if( !in_array( $this->db->getType(), $this->supportedDBs ) ) {
218218 throw new MWException( $this->db->getType() . " is not currently supported for unit testing." );
219219 }
220220 }
221 -
 221+
222222 public function getCliArg( $offset ) {
223 -
 223+
224224 if( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) {
225225 return MediaWikiPHPUnitCommand::$additionalOptions[$offset];
226226 }
227 -
 227+
228228 }
229 -
 229+
230230 public function setCliArg( $offset, $value ) {
231 -
 231+
232232 MediaWikiPHPUnitCommand::$additionalOptions[$offset] = $value;
233 -
 233+
234234 }
235235 }
236236
Index: trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php
@@ -1,36 +1,36 @@
22 <?php
33
44 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
5 -
6 - static $additionalOptions = array(
7 - 'regex=' => false,
 5+
 6+ static $additionalOptions = array(
 7+ 'regex=' => false,
88 'file=' => false,
99 'keep-uploads' => false,
1010 );
11 -
 11+
1212 public function __construct() {
1313 foreach( self::$additionalOptions as $option => $default ) {
1414 $this->longOptions[$option] = $option . 'Handler';
1515 }
16 -
 16+
1717 }
18 -
 18+
1919 public static function main( $exit = true ) {
20 - $command = new self;
21 - $command->run($_SERVER['argv'], $exit);
22 - }
23 -
24 - public function __call( $func, $args ) {
25 -
 20+ $command = new self;
 21+ $command->run($_SERVER['argv'], $exit);
 22+ }
 23+
 24+ public function __call( $func, $args ) {
 25+
2626 if( substr( $func, -7 ) == 'Handler' ) {
2727 if( is_null( $args[0] ) ) $args[0] = true; //Booleans
2828 self::$additionalOptions[substr( $func, 0, -7 ) ] = $args[0];
2929 }
3030 }
31 -
 31+
3232 public function showHelp() {
3333 parent::showHelp();
34 -
 34+
3535 print <<<EOT
3636
3737 ParserTest-specific options:
@@ -38,9 +38,9 @@
3939 --regex="<regex>" Only run parser tests that match the given regex
4040 --file="<filename>" Prints the version and exits.
4141 --keep-uploads Re-use the same upload directory for each test, don't delete it
42 -
4342
 43+
4444 EOT;
4545 }
46 -
 46+
4747 }
Index: trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php
@@ -12,14 +12,14 @@
1313 parent::setUp();
1414 $this->doLogin();
1515 }
16 -
 16+
1717 function getTokens() {
1818 return $this->getTokenList( $this->sysopUser );
1919 }
2020
2121 function addDBData() {
2222 $user = User::newFromName( 'UTBlockee' );
23 -
 23+
2424 if ( $user->getId() == 0 ) {
2525 $user->addToDatabase();
2626 $user->setPassword( 'UTBlockeePassword' );
@@ -29,23 +29,23 @@
3030 }
3131
3232 function testMakeNormalBlock() {
33 -
 33+
3434 $data = $this->getTokens();
35 -
 35+
3636 $user = User::newFromName( 'UTBlockee' );
37 -
 37+
3838 if ( !$user->getId() ) {
3939 $this->markTestIncomplete( "The user UTBlockee does not exist" );
4040 }
41 -
 41+
4242 if( !isset( $data[0]['query']['pages'] ) ) {
4343 $this->markTestIncomplete( "No block token found" );
4444 }
45 -
 45+
4646 $keys = array_keys( $data[0]['query']['pages'] );
4747 $key = array_pop( $keys );
4848 $pageinfo = $data[0]['query']['pages'][$key];
49 -
 49+
5050 $data = $this->doApiRequest( array(
5151 'action' => 'block',
5252 'user' => 'UTBlockee',
@@ -53,13 +53,13 @@
5454 'token' => $pageinfo['blocktoken'] ), $data );
5555
5656 $block = Block::newFromTarget('UTBlockee');
57 -
 57+
5858 $this->assertTrue( !is_null( $block ), 'Block is valid' );
5959
6060 $this->assertEquals( 'UTBlockee', (string)$block->getTarget() );
6161 $this->assertEquals( 'Some reason', $block->mReason );
6262 $this->assertEquals( 'infinity', $block->mExpiry );
63 -
 63+
6464 }
6565
6666 }
Index: trunk/phase3/includes/search/SearchMySQL.php
@@ -40,8 +40,8 @@
4141 parent::__construct( $db );
4242 }
4343
44 - /**
45 - * Parse the user's query and transform it into an SQL fragment which will
 44+ /**
 45+ * Parse the user's query and transform it into an SQL fragment which will
4646 * become part of a WHERE clause
4747 *
4848 * @param $filteredText string
@@ -419,7 +419,7 @@
420420 /**
421421 * Check MySQL server's ft_min_word_len setting so we know
422422 * if we need to pad short words...
423 - *
 423+ *
424424 * @return int
425425 */
426426 protected function minSearchLength() {
Index: trunk/phase3/includes/specials/SpecialBlock.php
@@ -48,7 +48,7 @@
4949
5050 /// @var Bool
5151 protected $alreadyBlocked;
52 -
 52+
5353 /// @var Array
5454 protected $preErrors = array();
5555
Index: trunk/phase3/includes/Block.php
@@ -21,7 +21,7 @@
2222 */
2323 class Block {
2424 /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName, $mAngryAutoblock;
25 -
 25+
2626 protected
2727 $mId,
2828 $mFromMaster,
@@ -262,7 +262,7 @@
263263 # This has the nice property that a /32 block is ranked equally with a
264264 # single-IP block, which is exactly what it is...
265265 $score = self::TYPE_RANGE - 1 + ( $size / 128 );
266 -
 266+
267267 } else {
268268 $score = $block->getType();
269269 }

Status & tagging log