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