6
class ApiBlockTest extends ApiTestCase {
13
function getTokens() {
14
return $this->getTokenList( self::$users['sysop'] );
17
function addDBData() {
18
$user = User::newFromName( 'UTApiBlockee' );
20
if ( $user->getId() == 0 ) {
21
$user->addToDatabase();
22
$user->setPassword( 'UTApiBlockeePassword' );
24
$user->saveSettings();
29
* This test has probably always been broken and use an invalid token
30
* Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
32
* Root cause is https://gerrit.wikimedia.org/r/3434
33
* Which made the Block/Unblock API to actually verify the token
34
* previously always considered valid (bug 34212).
38
function testMakeNormalBlock() {
40
$data = $this->getTokens();
42
$user = User::newFromName( 'UTApiBlockee' );
44
if ( !$user->getId() ) {
45
$this->markTestIncomplete( "The user UTApiBlockee does not exist" );
48
if( !isset( $data[0]['query']['pages'] ) ) {
49
$this->markTestIncomplete( "No block token found" );
52
$keys = array_keys( $data[0]['query']['pages'] );
53
$key = array_pop( $keys );
54
$pageinfo = $data[0]['query']['pages'][$key];
56
$data = $this->doApiRequest( array(
58
'user' => 'UTApiBlockee',
59
'reason' => 'Some reason',
60
'token' => $pageinfo['blocktoken'] ), $data, false, self::$users['sysop']->user );
62
$block = Block::newFromTarget('UTApiBlockee');
64
$this->assertTrue( !is_null( $block ), 'Block is valid' );
66
$this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
67
$this->assertEquals( 'Some reason', $block->mReason );
68
$this->assertEquals( 'infinity', $block->mExpiry );