Fix for r100905:
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiBlockTest.php
1 <?php
2
3 /**
4 * @group Database
5 */
6 class ApiBlockTest extends ApiTestCase {
7
8 function setUp() {
9 parent::setUp();
10 $this->doLogin();
11 }
12
13 function getTokens() {
14 return $this->getTokenList( self::$users['sysop'] );
15 }
16
17 function addDBData() {
18 $user = User::newFromName( 'UTApiBlockee' );
19
20 if ( $user->getId() == 0 ) {
21 $user->addToDatabase();
22 $user->setPassword( 'UTApiBlockeePassword' );
23
24 $user->saveSettings();
25 }
26 }
27
28 function testMakeNormalBlock() {
29
30 $data = $this->getTokens();
31
32 $user = User::newFromName( 'UTApiBlockee' );
33
34 if ( !$user->getId() ) {
35 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
36 }
37
38 if( !isset( $data[0]['query']['pages'] ) ) {
39 $this->markTestIncomplete( "No block token found" );
40 }
41
42 $keys = array_keys( $data[0]['query']['pages'] );
43 $key = array_pop( $keys );
44 $pageinfo = $data[0]['query']['pages'][$key];
45
46 $data = $this->doApiRequest( array(
47 'action' => 'block',
48 'user' => 'UTApiBlockee',
49 'reason' => 'Some reason',
50 'token' => $pageinfo['blocktoken'] ), $data, false, self::$users['sysop']->user );
51
52 $block = Block::newFromTarget('UTApiBlockee');
53
54 $this->assertTrue( !is_null( $block ), 'Block is valid' );
55
56 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
57 $this->assertEquals( 'Some reason', $block->mReason );
58 $this->assertEquals( 'infinity', $block->mExpiry );
59
60 }
61
62 }