MediaWiki  REL1_19
ApiBlockTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class ApiBlockTest extends ApiTestCase {
00007 
00008         function setUp() {
00009                 parent::setUp();
00010                 $this->doLogin();
00011         }
00012 
00013         function getTokens() {
00014                 return $this->getTokenList( self::$users['sysop'] );
00015         }
00016 
00017         function addDBData() {
00018                 $user = User::newFromName( 'UTApiBlockee' );
00019 
00020                 if ( $user->getId() == 0 ) {
00021                         $user->addToDatabase();
00022                         $user->setPassword( 'UTApiBlockeePassword' );
00023 
00024                         $user->saveSettings();
00025                 }
00026         }
00027 
00038         function testMakeNormalBlock() {
00039 
00040                 $data = $this->getTokens();
00041 
00042                 $user = User::newFromName( 'UTApiBlockee' );
00043 
00044                 if ( !$user->getId() ) {
00045                         $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
00046                 }
00047 
00048                 if( !isset( $data[0]['query']['pages'] ) ) {
00049                         $this->markTestIncomplete( "No block token found" );
00050                 }
00051 
00052                 $keys = array_keys( $data[0]['query']['pages'] );
00053                 $key = array_pop( $keys );
00054                 $pageinfo = $data[0]['query']['pages'][$key];
00055 
00056                 $data = $this->doApiRequest( array(
00057                         'action' => 'block',
00058                         'user' => 'UTApiBlockee',
00059                         'reason' => 'Some reason',
00060                         'token' => $pageinfo['blocktoken'] ), $data, false, self::$users['sysop']->user );
00061 
00062                 $block = Block::newFromTarget('UTApiBlockee');
00063 
00064                 $this->assertTrue( !is_null( $block ), 'Block is valid' );
00065 
00066                 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
00067                 $this->assertEquals( 'Some reason', $block->mReason );
00068                 $this->assertEquals( 'infinity', $block->mExpiry );
00069 
00070         }
00071 
00072 }