MediaWiki  REL1_20
ApiBlockTest.php
Go to the documentation of this file.
00001 <?php
00002 
00007 class ApiBlockTest extends ApiTestCase {
00008 
00009         function setUp() {
00010                 parent::setUp();
00011                 $this->doLogin();
00012         }
00013 
00014         function getTokens() {
00015                 return $this->getTokenList( self::$users['sysop'] );
00016         }
00017 
00018         function addDBData() {
00019                 $user = User::newFromName( 'UTApiBlockee' );
00020 
00021                 if ( $user->getId() == 0 ) {
00022                         $user->addToDatabase();
00023                         $user->setPassword( 'UTApiBlockeePassword' );
00024 
00025                         $user->saveSettings();
00026                 }
00027         }
00028 
00037         function testMakeNormalBlock() {
00038 
00039                 $data = $this->getTokens();
00040 
00041                 $user = User::newFromName( 'UTApiBlockee' );
00042 
00043                 if ( !$user->getId() ) {
00044                         $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
00045                 }
00046 
00047                 if( !isset( $data[0]['query']['pages'] ) ) {
00048                         $this->markTestIncomplete( "No block token found" );
00049                 }
00050 
00051                 $keys = array_keys( $data[0]['query']['pages'] );
00052                 $key = array_pop( $keys );
00053                 $pageinfo = $data[0]['query']['pages'][$key];
00054 
00055                 $data = $this->doApiRequest( array(
00056                         'action' => 'block',
00057                         'user' => 'UTApiBlockee',
00058                         'reason' => 'Some reason',
00059                         'token' => $pageinfo['blocktoken'] ), null, false, self::$users['sysop']->user );
00060 
00061                 $block = Block::newFromTarget('UTApiBlockee');
00062 
00063                 $this->assertTrue( !is_null( $block ), 'Block is valid' );
00064 
00065                 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
00066                 $this->assertEquals( 'Some reason', $block->mReason );
00067                 $this->assertEquals( 'infinity', $block->mExpiry );
00068 
00069         }
00070 
00074         function testGetTokenUsingABlockingAction( $action ) {
00075                 $data = $this->doApiRequest(
00076                         array(
00077                                 'action' => $action,
00078                                 'user' => 'UTApiBlockee',
00079                                 'gettoken' => '' ),
00080                         null,
00081                         false,
00082                         self::$users['sysop']->user
00083                 );
00084                 $this->assertEquals( 34, strlen( $data[0][$action]["{$action}token"] ) );
00085         }
00086 
00095         function testBlockingActionWithNoToken( $action ) {
00096                 $this->doApiRequest(
00097                         array(
00098                                 'action' => $action,
00099                                 'user' => 'UTApiBlockee',
00100                                 'reason' => 'Some reason',
00101                                 ),
00102                         null,
00103                         false,
00104                         self::$users['sysop']->user
00105                 );
00106         }
00107 
00111         function provideBlockUnblockAction() {
00112                 return array(
00113                         array( 'block'   ),
00114                         array( 'unblock' ),
00115                 );
00116         }
00117 }