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