Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / api / ApiBlockTest.php
blobffd2f5ed75cc3196942d21c79605326cdaa1fe11
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 TestUser::setPasswordForUser( $user, 'UTApiBlockeePassword' );
27 $user->saveSettings();
31 /**
32 * This test has probably always been broken and use an invalid token
33 * Bug tracking brokenness is https://phabricator.wikimedia.org/T37646
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 (T36212).
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']->getUser() );
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']->getUser()