a7dbcf8384e214e68e3b6e92be2007607cfb54a9
[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 function testMakeNormalBlock() {
32
33 $data = $this->getTokens();
34
35 $user = User::newFromName( 'UTBlockee' );
36
37 if ( !$user->getId() ) {
38 $this->markTestIncomplete( "The user UTBlockee does not exist" );
39 }
40
41 if( !isset( $data[0]['query']['pages'] ) ) {
42 $this->markTestIncomplete( "No block token found" );
43 }
44
45 $keys = array_keys( $data[0]['query']['pages'] );
46 $key = array_pop( $keys );
47 $pageinfo = $data[0]['query']['pages'][$key];
48
49 $data = $this->doApiRequest( array(
50 'action' => 'block',
51 'user' => 'UTBlockee',
52 'reason' => 'Some reason',
53 'token' => $pageinfo['blocktoken'] ), $data );
54
55 $block = Block::newFromTarget('UTBlockee');
56
57 $this->assertTrue( !is_null( $block ), 'Block is valid' );
58
59 $this->assertEquals( 'UTBlockee', (string)$block->getTarget() );
60 $this->assertEquals( 'Some reason', $block->mReason );
61 $this->assertEquals( 'infinity', $block->mExpiry );
62
63 }
64
65 }