wiki.techinc.nl/tests/phpunit/includes/api/ApiBlockTest.php

63 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/**
* @group Database
*/
class ApiBlockTest extends ApiTestCase {
function setUp() {
parent::setUp();
$this->doLogin();
}
2011-06-02 19:32:45 +00:00
function getTokens() {
return $this->getTokenList( self::$users['sysop'] );
}
function addDBData() {
$user = User::newFromName( 'UTBlockee' );
2011-06-02 19:32:45 +00:00
if ( $user->getId() == 0 ) {
$user->addToDatabase();
$user->setPassword( 'UTBlockeePassword' );
$user->saveSettings();
}
}
function testMakeNormalBlock() {
2011-06-02 19:32:45 +00:00
$data = $this->getTokens();
2011-06-02 19:32:45 +00:00
$user = User::newFromName( 'UTBlockee' );
2011-06-02 19:32:45 +00:00
if ( !$user->getId() ) {
$this->markTestIncomplete( "The user UTBlockee does not exist" );
}
2011-06-02 19:32:45 +00:00
if( !isset( $data[0]['query']['pages'] ) ) {
$this->markTestIncomplete( "No block token found" );
}
2011-06-02 19:32:45 +00:00
$keys = array_keys( $data[0]['query']['pages'] );
$key = array_pop( $keys );
$pageinfo = $data[0]['query']['pages'][$key];
2011-06-02 19:32:45 +00:00
$data = $this->doApiRequest( array(
'action' => 'block',
'user' => 'UTBlockee',
'reason' => BlockTest::REASON,
'token' => $pageinfo['blocktoken'] ), $data );
$block = Block::newFromTarget('UTBlockee');
2011-06-02 19:32:45 +00:00
$this->assertTrue( !is_null( $block ), 'Block is valid' );
$this->assertEquals( 'UTBlockee', (string)$block->getTarget() );
$this->assertEquals( 'Some reason', $block->mReason );
$this->assertEquals( 'infinity', $block->mExpiry );
2011-06-02 19:32:45 +00:00
}
}