wiki.techinc.nl/tests/phpunit/includes/api/ApiBlockTest.php
Happy-melon 6dbcdc1be0 Blame hashar for this giant commit; he teased me for making so many smaller ones earlier... :D
* Internalise $mAddress/$mUser, $mBy/$mByName, $mEnableAutoblock, $mId as getTarget(), getBlockers(), isAutoblocking(), getId().  
* This required editing AbuseFilter and CheckUser backwards-incompatibly, so push the rest of the changes out to those extensions.
* Attack the evil 14-parameter constructor and gratuitously-confusing newFromDB( $notVeryImportantParameter, $moreImportantParameter)
* Reimplement the hack for bug 13611 in a slightly less fragile fashion; could still do with further cleanup, but then again the login frontend is its own can of worms... :S
* Remove transitionary getTargetAndType() and newFromTargetAndType() methods
* Some optimisation in parseTarget()
* Fix the broken phpunit test mentioned in r84251
2011-03-21 19:12:41 +00:00

67 lines
1.4 KiB
PHP

<?php
require_once dirname( __FILE__ ) . '/ApiSetup.php';
/**
* @group Database
* @group Destructive
*/
class ApiBlockTest extends ApiTestSetup {
function setUp() {
parent::setUp();
$this->doLogin();
}
function getTokens() {
return $this->getTokenList( $this->sysopUser );
}
function addDBData() {
$user = User::newFromName( 'UTBlockee' );
if ( $user->getId() == 0 ) {
$user->addToDatabase();
$user->setPassword( 'UTBlockeePassword' );
$user->saveSettings();
}
}
function testMakeNormalBlock() {
$data = $this->getTokens();
$user = User::newFromName( 'UTBlockee' );
if ( !$user->getId() ) {
$this->markTestIncomplete( "The user UTBlockee does not exist" );
}
if( !isset( $data[0]['query']['pages'] ) ) {
$this->markTestIncomplete( "No block token found" );
}
$keys = array_keys( $data[0]['query']['pages'] );
$key = array_pop( $keys );
$pageinfo = $data[0]['query']['pages'][$key];
$data = $this->doApiRequest( array(
'action' => 'block',
'user' => 'UTBlockee',
'reason' => 'Some reason',
'token' => $pageinfo['blocktoken'] ), $data );
$block = Block::newFromTarget('UTBlockee');
$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 );
}
}