Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / api / ApiBlockTest.php
blobd98eec6a67363b58c8d308fdd29392fe1eba314c
1 <?php
3 /**
4 * @group API
5 * @group Database
6 * @group medium
8 * @covers ApiBlock
9 */
10 class ApiBlockTest extends ApiTestCase {
11 protected function setUp() {
12 parent::setUp();
13 $this->doLogin();
16 protected function getTokens() {
17 return $this->getTokenList( self::$users['sysop'] );
20 function addDBData() {
21 $user = User::newFromName( 'UTApiBlockee' );
23 if ( $user->getId() == 0 ) {
24 $user->addToDatabase();
25 $user->setPassword( 'UTApiBlockeePassword' );
27 $user->saveSettings();
31 /**
32 * This test has probably always been broken and use an invalid token
33 * Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
35 * Root cause is https://gerrit.wikimedia.org/r/3434
36 * Which made the Block/Unblock API to actually verify the token
37 * previously always considered valid (bug 34212).
39 public function testMakeNormalBlock() {
40 $tokens = $this->getTokens();
42 $user = User::newFromName( 'UTApiBlockee' );
44 if ( !$user->getId() ) {
45 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
48 if ( !array_key_exists( 'blocktoken', $tokens ) ) {
49 $this->markTestIncomplete( "No block token found" );
52 $this->doApiRequest( array(
53 'action' => 'block',
54 'user' => 'UTApiBlockee',
55 'reason' => 'Some reason',
56 'token' => $tokens['blocktoken'] ), null, false, self::$users['sysop']->user );
58 $block = Block::newFromTarget( 'UTApiBlockee' );
60 $this->assertTrue( !is_null( $block ), 'Block is valid' );
62 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
63 $this->assertEquals( 'Some reason', $block->mReason );
64 $this->assertEquals( 'infinity', $block->mExpiry );
67 /**
68 * @expectedException UsageException
69 * @expectedExceptionMessage The token parameter must be set
71 public function testBlockingActionWithNoToken( ) {
72 $this->doApiRequest(
73 array(
74 'action' => 'block',
75 'user' => 'UTApiBlockee',
76 'reason' => 'Some reason',
78 null,
79 false,
80 self::$users['sysop']->user