2011-01-02 19:58:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-02 13:33:43 +00:00
|
|
|
* @group API
|
2011-01-02 19:58:27 +00:00
|
|
|
* @group Database
|
2013-01-18 19:02:28 +00:00
|
|
|
* @group medium
|
2013-10-23 16:01:33 +00:00
|
|
|
*
|
|
|
|
|
* @covers ApiBlock
|
2011-01-02 19:58:27 +00:00
|
|
|
*/
|
2011-07-01 16:34:02 +00:00
|
|
|
class ApiBlockTest extends ApiTestCase {
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2011-01-02 19:58:27 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
$this->doLogin();
|
|
|
|
|
}
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2013-10-23 16:01:33 +00:00
|
|
|
protected function getTokens() {
|
2011-07-01 16:34:02 +00:00
|
|
|
return $this->getTokenList( self::$users['sysop'] );
|
2011-01-02 19:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addDBData() {
|
2011-09-12 22:18:33 +00:00
|
|
|
$user = User::newFromName( 'UTApiBlockee' );
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2011-01-02 19:58:27 +00:00
|
|
|
if ( $user->getId() == 0 ) {
|
|
|
|
|
$user->addToDatabase();
|
2011-09-12 22:18:33 +00:00
|
|
|
$user->setPassword( 'UTApiBlockeePassword' );
|
2011-01-02 19:58:27 +00:00
|
|
|
|
|
|
|
|
$user->saveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-28 21:22:29 +00:00
|
|
|
|
2012-04-03 13:05:50 +00:00
|
|
|
/**
|
|
|
|
|
* This test has probably always been broken and use an invalid token
|
|
|
|
|
* Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
|
|
|
|
|
*
|
|
|
|
|
* Root cause is https://gerrit.wikimedia.org/r/3434
|
|
|
|
|
* Which made the Block/Unblock API to actually verify the token
|
|
|
|
|
* previously always considered valid (bug 34212).
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testMakeNormalBlock() {
|
2013-08-05 19:31:45 +00:00
|
|
|
$tokens = $this->getTokens();
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2011-09-12 22:18:33 +00:00
|
|
|
$user = User::newFromName( 'UTApiBlockee' );
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2011-01-02 19:58:27 +00:00
|
|
|
if ( !$user->getId() ) {
|
2011-09-12 22:18:33 +00:00
|
|
|
$this->markTestIncomplete( "The user UTApiBlockee does not exist" );
|
2011-01-02 19:58:27 +00:00
|
|
|
}
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2013-08-05 19:31:45 +00:00
|
|
|
if ( !array_key_exists( 'blocktoken', $tokens ) ) {
|
2011-01-02 19:58:27 +00:00
|
|
|
$this->markTestIncomplete( "No block token found" );
|
|
|
|
|
}
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2013-04-26 07:48:46 +00:00
|
|
|
$this->doApiRequest( array(
|
2011-01-02 19:58:27 +00:00
|
|
|
'action' => 'block',
|
2011-09-12 22:18:33 +00:00
|
|
|
'user' => 'UTApiBlockee',
|
2011-08-08 16:08:48 +00:00
|
|
|
'reason' => 'Some reason',
|
2013-08-05 19:31:45 +00:00
|
|
|
'token' => $tokens['blocktoken'] ), null, false, self::$users['sysop']->user );
|
2011-03-21 19:12:41 +00:00
|
|
|
|
2013-02-14 11:56:23 +00:00
|
|
|
$block = Block::newFromTarget( 'UTApiBlockee' );
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2011-01-02 19:58:27 +00:00
|
|
|
$this->assertTrue( !is_null( $block ), 'Block is valid' );
|
|
|
|
|
|
2011-09-12 22:18:33 +00:00
|
|
|
$this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
|
2011-01-02 19:58:27 +00:00
|
|
|
$this->assertEquals( 'Some reason', $block->mReason );
|
2011-11-10 09:36:18 +00:00
|
|
|
$this->assertEquals( 'infinity', $block->mExpiry );
|
2011-01-02 19:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-03 20:02:27 +00:00
|
|
|
/**
|
|
|
|
|
* @expectedException UsageException
|
2013-10-23 16:01:33 +00:00
|
|
|
* @expectedExceptionMessage The token parameter must be set
|
2012-04-03 20:02:27 +00:00
|
|
|
*/
|
2015-06-16 19:06:19 +00:00
|
|
|
public function testBlockingActionWithNoToken() {
|
2012-04-03 20:02:27 +00:00
|
|
|
$this->doApiRequest(
|
|
|
|
|
array(
|
2013-10-23 16:01:33 +00:00
|
|
|
'action' => 'block',
|
2012-04-03 20:02:27 +00:00
|
|
|
'user' => 'UTApiBlockee',
|
|
|
|
|
'reason' => 'Some reason',
|
2013-02-14 11:56:23 +00:00
|
|
|
),
|
2012-04-03 20:02:27 +00:00
|
|
|
null,
|
|
|
|
|
false,
|
|
|
|
|
self::$users['sysop']->user
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-01-02 19:58:27 +00:00
|
|
|
}
|