Merge "Moved Preferences::trySetUserEmail() to User::setEmailWithConfirmation()"
[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 /**
30 * This test has probably always been broken and use an invalid token
31 * Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
32 *
33 * Root cause is https://gerrit.wikimedia.org/r/3434
34 * Which made the Block/Unblock API to actually verify the token
35 * previously always considered valid (bug 34212).
36 *
37 * @group Broken
38 */
39 function testMakeNormalBlock() {
40
41 $data = $this->getTokens();
42
43 $user = User::newFromName( 'UTApiBlockee' );
44
45 if ( !$user->getId() ) {
46 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
47 }
48
49 if( !isset( $data[0]['query']['pages'] ) ) {
50 $this->markTestIncomplete( "No block token found" );
51 }
52
53 $keys = array_keys( $data[0]['query']['pages'] );
54 $key = array_pop( $keys );
55 $pageinfo = $data[0]['query']['pages'][$key];
56
57 $data = $this->doApiRequest( array(
58 'action' => 'block',
59 'user' => 'UTApiBlockee',
60 'reason' => 'Some reason',
61 'token' => $pageinfo['blocktoken'] ), $data, false, self::$users['sysop']->user );
62
63 $block = Block::newFromTarget('UTApiBlockee');
64
65 $this->assertTrue( !is_null( $block ), 'Block is valid' );
66
67 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
68 $this->assertEquals( 'Some reason', $block->mReason );
69 $this->assertEquals( 'infinity', $block->mExpiry );
70
71 }
72
73 }