r79499 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79498‎ | r79499 | r79500 >
Date:19:58, 2 January 2011
Author:soxred93
Status:ok
Tags:
Comment:
-Add &watchuser option to ApiBlock
-Write tests for ApiBlock
Modified paths:
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php
@@ -0,0 +1,67 @@
 2+<?php
 3+
 4+require_once dirname( __FILE__ ) . '/ApiSetup.php';
 5+
 6+/**
 7+ * @group Database
 8+ * @group Destructive
 9+ */
 10+class ApiBlockTest extends ApiTestSetup {
 11+
 12+ function setUp() {
 13+ parent::setUp();
 14+ $this->doLogin();
 15+ }
 16+
 17+ function getTokens() {
 18+ return $this->getTokenList( $this->sysopUser );
 19+ }
 20+
 21+ function addDBData() {
 22+ $user = User::newFromName( 'UTBlockee' );
 23+
 24+ if ( $user->getId() == 0 ) {
 25+ $user->addToDatabase();
 26+ $user->setPassword( 'UTBlockeePassword' );
 27+
 28+ $user->saveSettings();
 29+ }
 30+ }
 31+
 32+
 33+
 34+ function testMakeNormalBlock() {
 35+
 36+ $data = $this->getTokens();
 37+
 38+ $user = User::newFromName( 'UTBlockee' );
 39+
 40+ if ( !$user->getId() ) {
 41+ $this->markTestIncomplete( "The user UTBlockee does not exist" );
 42+ }
 43+
 44+ if( !isset( $data[0]['query']['pages'] ) ) {
 45+ $this->markTestIncomplete( "No block token found" );
 46+ }
 47+
 48+ $keys = array_keys( $data[0]['query']['pages'] );
 49+ $key = array_pop( $keys );
 50+ $pageinfo = $data[0]['query']['pages'][$key];
 51+
 52+ $data = $this->doApiRequest( array(
 53+ 'action' => 'block',
 54+ 'user' => 'UTBlockee',
 55+ 'reason' => 'Some reason',
 56+ 'token' => $pageinfo['blocktoken'] ), $data );
 57+
 58+ $block = Block::newFromDB('UTBlockee');
 59+
 60+ $this->assertTrue( !is_null( $block ), 'Block is valid' );
 61+
 62+ $this->assertEquals( 'UTBlockee', $block->mAddress );
 63+ $this->assertEquals( 'Some reason', $block->mReason );
 64+ $this->assertEquals( 'infinity', $block->mExpiry );
 65+
 66+ }
 67+
 68+}
Property changes on: trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php
___________________________________________________________________
Added: svn:eol-style
169 + native
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -90,6 +90,7 @@
9191 $form->BlockHideName = $params['hidename'];
9292 $form->BlockAllowUsertalk = $params['allowusertalk'] && $wgBlockAllowsUTEdit;
9393 $form->BlockReblock = $params['reblock'];
 94+ $form->BlockWatchUser = $params['watchuser'];
9495
9596 $userID = $expiry = null;
9697 $retval = $form->doBlock( $userID, $expiry );
@@ -120,6 +121,9 @@
121122 if ( $params['allowusertalk'] ) {
122123 $res['allowusertalk'] = '';
123124 }
 125+ if ( $params['watchuser'] ) {
 126+ $res['watchuser'] = '';
 127+ }
124128
125129 $this->getResult()->addValue( null, $this->getModuleName(), $res );
126130 }
@@ -149,6 +153,7 @@
150154 'hidename' => false,
151155 'allowusertalk' => false,
152156 'reblock' => false,
 157+ 'watchuser' => false,
153158 );
154159 }
155160
@@ -166,6 +171,7 @@
167172 'hidename' => 'Hide the username from the block log. (Requires the "hideuser" right.)',
168173 'allowusertalk' => 'Allow the user to edit their own talk page (depends on $wgBlockAllowsUTEdit)',
169174 'reblock' => 'If the user is already blocked, overwrite the existing block',
 175+ 'watchuser' => 'Watch the user/IP\'s user and talk pages',
170176 );
171177 }
172178

Follow-up revisions

RevisionCommit summaryAuthorDate
r79500Forgot the RELEASE-NOTES (woo, 500!)soxred9320:00, 2 January 2011

Status & tagging log