*/
class Block {
/* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName, $mAngryAutoblock;
-
+
protected
$mId,
$mFromMaster,
# This has the nice property that a /32 block is ranked equally with a
# single-IP block, which is exactly what it is...
$score = self::TYPE_RANGE - 1 + ( $size / 128 );
-
+
} else {
$score = $block->getType();
}
parent::__construct( $db );
}
- /**
- * Parse the user's query and transform it into an SQL fragment which will
+ /**
+ * Parse the user's query and transform it into an SQL fragment which will
* become part of a WHERE clause
*
* @param $filteredText string
/**
* Check MySQL server's ft_min_word_len setting so we know
* if we need to pad short words...
- *
+ *
* @return int
*/
protected function minSearchLength() {
/// @var Bool
protected $alreadyBlocked;
-
+
/// @var Array
protected $preErrors = array();
<?php
class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
-
- static $additionalOptions = array(
- 'regex=' => false,
+
+ static $additionalOptions = array(
+ 'regex=' => false,
'file=' => false,
'keep-uploads' => false,
);
-
+
public function __construct() {
foreach( self::$additionalOptions as $option => $default ) {
$this->longOptions[$option] = $option . 'Handler';
}
-
+
}
-
+
public static function main( $exit = true ) {
- $command = new self;
- $command->run($_SERVER['argv'], $exit);
- }
-
- public function __call( $func, $args ) {
-
+ $command = new self;
+ $command->run($_SERVER['argv'], $exit);
+ }
+
+ public function __call( $func, $args ) {
+
if( substr( $func, -7 ) == 'Handler' ) {
if( is_null( $args[0] ) ) $args[0] = true; //Booleans
self::$additionalOptions[substr( $func, 0, -7 ) ] = $args[0];
}
}
-
+
public function showHelp() {
parent::showHelp();
-
+
print <<<EOT
ParserTest-specific options:
--regex="<regex>" Only run parser tests that match the given regex
--file="<filename>" Prints the version and exits.
--keep-uploads Re-use the same upload directory for each test, don't delete it
-
+
EOT;
}
-
+
}
*/
const DB_PREFIX = 'unittest_';
const ORA_DB_PREFIX = 'ut_';
-
+
protected $supportedDBs = array(
'mysql',
'sqlite',
$this->backupGlobals = false;
$this->backupStaticAttributes = false;
}
-
+
function run( PHPUnit_Framework_TestResult $result = NULL ) {
/* Some functions require some kind of caching, and will end up using the db,
* which we can't allow, as that would open a new connection for mysql.
ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
if( $this->needsDB() ) {
-
+
global $wgDBprefix;
-
+
$this->db = wfGetDB( DB_MASTER );
-
+
$this->checkDbIsSupported();
$this->oldTablePrefix = $wgDBprefix;
$this->addCoreDBData();
$this->addDBData();
-
+
parent::run( $result );
$this->resetDB();
function dbPrefix() {
return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
}
-
+
function needsDB() {
$rc = new ReflectionClass( $this );
return strpos( $rc->getDocComment(), '@group Database' ) !== false;
* implement this method and do so
*/
function addDBData() {}
-
+
private function addCoreDBData() {
User::resetIdByNameCache();
//Make sysop user
$user = User::newFromName( 'UTSysop' );
-
+
if ( $user->idForName() == 0 ) {
$user->addToDatabase();
$user->setPassword( 'UTSysopPassword' );
$user->saveSettings();
}
-
+
//Make 1 page with 1 revision
$article = new Article( Title::newFromText( 'UTPage' ) );
$article->doEdit( 'UTContent',
false,
User::newFromName( 'UTSysop' ) );
}
-
+
private function initDB() {
global $wgDBprefix;
if ( $wgDBprefix === $this->dbPrefix() ) {
private function assertEmpty2( $value, $msg ) {
return $this->assertTrue( $value == '', $msg );
}
-
+
static private function unprefixTable( $tableName ) {
global $wgDBprefix;
return substr( $tableName, strlen( $wgDBprefix ) );
}
return $tables;
}
-
+
protected function checkDbIsSupported() {
if( !in_array( $this->db->getType(), $this->supportedDBs ) ) {
throw new MWException( $this->db->getType() . " is not currently supported for unit testing." );
}
}
-
+
public function getCliArg( $offset ) {
-
+
if( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) {
return MediaWikiPHPUnitCommand::$additionalOptions[$offset];
}
-
+
}
-
+
public function setCliArg( $offset, $value ) {
-
+
MediaWikiPHPUnitCommand::$additionalOptions[$offset] = $value;
-
+
}
}
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' );
}
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',
'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 );
-
+
}
}