Sets a global, maintaining a stashed version of the previous global to be restored in tearDownThe key is added to the array of globals that will be reset afterwards in the tearDown().
'mysql',
'sqlite',
'postgres',
'oracle'
);
parent::__construct(
$name, $data, $dataName );
$this->backupGlobals = false;
$this->backupStaticAttributes = false;
}
public function run( PHPUnit_Framework_TestResult
$result =
null ) {
$needsResetDB = false;
$logName = get_class( $this ) . '::' . $this->getName( false );
self::$useTemporaryTables = !$this->
getCliArg(
'use-normal-tables' );
self::$reuseDB = $this->
getCliArg(
'reuse-db' );
if ( !self::$dbSetup ) {
}
}
$needsResetDB = true;
}
if ( $needsResetDB ) {
}
}
}
$fileName = tempnam(
wfTempDir(),
'MW_PHPUnit_' . get_class( $this ) .
'_' );
$this->tmpFiles[] = $fileName;
return $fileName;
}
unlink( $fileName );
return $fileName;
}
protected function setUp() {
parent::setUp();
$this->called['setUp'] = 1;
$this->phpErrorLevel = intval( ini_get( 'error_reporting' ) );
foreach ( $this->tmpFiles
as $fileName ) {
if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) {
unlink( $fileName );
} elseif ( is_dir( $fileName ) ) {
}
}
if ( $this->
needsDB() && $this->db ) {
while ( $this->db->trxLevel() > 0 ) {
$this->db->rollback();
}
$this->db->ignoreErrors( false );
}
}
foreach ( $this->tmpFiles
as $fileName ) {
if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) {
unlink( $fileName );
} elseif ( is_dir( $fileName ) ) {
}
}
if ( $this->
needsDB() && $this->db ) {
while ( $this->db->trxLevel() > 0 ) {
$this->db->rollback();
}
$this->db->ignoreErrors( false );
}
foreach ( $this->mwGlobals
as $key =>
$value ) {
}
$this->mwGlobals =
array();
ini_set( 'error_reporting', $this->phpErrorLevel );
$oldHex = strtoupper( dechex( $this->phpErrorLevel ) );
$message = "PHP error_reporting setting was left dirty: was 0x$oldHex before test, 0x$newHex after test!";
}
parent::tearDown();
}
$this->assertArrayHasKey( 'setUp', $this->called,
get_called_class() . "::setUp() must call parent::setUp()"
);
}
if ( is_string( $pairs ) ) {
}
}
}
if ( is_string( $globalKeys ) ) {
$globalKeys =
array( $globalKeys );
}
foreach ( $globalKeys
as $globalKey ) {
if ( !array_key_exists( $globalKey, $this->mwGlobals ) ) {
if ( !array_key_exists( $globalKey,
$GLOBALS ) ) {
throw new Exception( "Global with key {$globalKey} doesn't exist and cant be stashed" );
}
try {
$this->mwGlobals[$globalKey] = unserialize( serialize(
$GLOBALS[$globalKey] ) );
}
$this->mwGlobals[$globalKey] =
$GLOBALS[$globalKey];
}
}
}
}
$merged = $values;
} else {
throw new MWException(
"MW global $name is not an array." );
}
foreach ( $values
as $k => $v ) {
$merged[$k] = $v;
}
}
}
}
# if the test says it uses database tables, it needs the database
if ( $this->tablesUsed ) {
return true;
}
# if the test says it belongs to the Database group, it needs the database
$rc = new ReflectionClass( $this );
if ( preg_match( '/@group +Database/im', $rc->getDocComment() ) ) {
return true;
}
return false;
}
}
if ( $this->db->getType() == 'oracle' ) {
# Insert 0 user to prevent FK violations
# Anonymous user
$this->db->insert(
'user',
array(
'user_id' => 0,
'user_name' =>
'Anonymous' ), __METHOD__,
array(
'IGNORE' ) );
# Insert 0 page to prevent FK violations
# Blank page
$this->db->insert(
'page',
array(
'page_id' => 0,
'page_namespace' => 0,
'page_title' => ' ',
'page_restrictions' => null,
'page_counter' => 0,
'page_is_redirect' => 0,
'page_is_new' => 0,
'page_random' => 0,
'page_touched' => $this->db->timestamp(),
'page_latest' => 0,
'page_len' => 0 ), __METHOD__,
array(
'IGNORE' ) );
}
if (
$user->idForName() == 0 ) {
$user->setPassword(
'UTSysopPassword' );
$user->addGroup(
'sysop' );
$user->addGroup(
'bureaucrat' );
}
if ( !$page->getId() == 0 ) {
$page->doEditContent(
'UTPageSummary',
false,
}
}
if ( !self::$dbSetup ) {
return;
}
self::$oldTablePrefix = false;
self::$dbSetup = false;
}
if ( $wgDBprefix === $prefix ) {
'Cannot run unit tests, the database prefix is already "' . $prefix . '"' );
}
if ( self::$dbSetup ) {
return;
}
$dbClone->useTemporaryTables( self::$useTemporaryTables );
self::$dbSetup = true;
self::$oldTablePrefix = $wgDBprefix;
return;
} else {
$dbClone->cloneTableStructure();
}
$db->
query(
'BEGIN FILL_WIKI_INFO; END;' );
}
}
if ( $this->db ) {
if ( $this->db->getType() == 'oracle' ) {
if ( self::$useTemporaryTables ) {
} else {
foreach ( $this->tablesUsed
as $tbl ) {
if ( $tbl == 'interwiki' ) {
continue;
}
$this->db->query( 'TRUNCATE TABLE ' . $this->db->tableName( $tbl ), __METHOD__ );
}
}
} else {
foreach ( $this->tablesUsed
as $tbl ) {
if ( $tbl == 'interwiki' || $tbl == 'user' ) {
continue;
}
$this->db->delete( $tbl, '*', __METHOD__ );
}
}
}
}
static $compatibility =
array(
'assertEmpty' => 'assertEmpty2',
);
if ( isset( $compatibility[$func] ) ) {
return call_user_func_array(
array( $this, $compatibility[$func] ),
$args );
} else {
throw new MWException(
"Called non-existant $func method on "
. get_class( $this ) );
}
}
return $this->assertTrue(
$value ==
'', $msg );
}
return substr( $tableName, strlen( $wgDBprefix ) );
}
return strpos( $table, 'unittest_' ) !== 0;
}
# bug 43571: cannot clone VIEWs under MySQL
}
unset(
$tables[
'searchindex_content'] );
unset(
$tables[
'searchindex_segdir'] );
unset(
$tables[
'searchindex_segments'] );
}
}
throw new MWException( $this->db->getType() .
" is not currently supported for unit testing." );
}
}
}
}
}
}
protected function assertSelect( $table, $fields, $condition,
array $expectedRows ) {
throw new MWException(
'When testing database state, the test cases\'s needDB()' .
' method should return true. Use @group Database or $this->tablesUsed.' );
}
$i = 0;
foreach ( $expectedRows
as $expected ) {
$i += 1;
$this->assertNotEmpty( $r, "row #$i missing" );
$this->assertEquals( $expected, $r, "row #$i mismatches" );
}
$this->assertFalse( $r, "found extra row (after #$i)" );
}
return array_map(
function ( $element ) {
return array( $element );
},
$elements
);
}
if ( !$ordered ) {
}
if ( !$named ) {
$expected = array_values( $expected );
$actual = array_values( $actual );
}
call_user_func_array(
array( $this,
'assertEquals' ),
array_merge(
array( $expected, $actual ), array_slice( func_get_args(), 4 ) )
);
}
$expected = str_replace( '>', ">\n", $expected );
$actual = str_replace( '>', ">\n", $actual );
$this->assertEquals( $expected, $actual, $msg );
}
uasort(
$array,
function ( $a, $b ) {
return serialize( $a ) > serialize( $b ) ? 1 : -1;
}
);
}
if ( !is_array( $r ) ) {
return;
}
foreach ( $r
as $k => $v ) {
if ( is_string( $k ) ) {
unset( $r[$k] );
}
}
}
$this->assertTrue( true, $message );
} else {
}
}
if ( class_exists(
$type ) || interface_exists(
$type ) ) {
$this->assertInstanceOf(
$type, $actual, $message );
} else {
$this->assertInternalType(
$type, $actual, $message );
}
}
global $wgNamespaceContentModels;
if ( isset( $wgNamespaceContentModels[$ns] ) ) {
}
return true;
}
global $wgNamespaceContentModels;
static $wikitextNS = null;
if ( $wikitextNS !== null ) {
return $wikitextNS;
}
if ( !isset( $wgNamespaceContentModels[
NS_MAIN] ) ) {
}
) );
) );
} );
if ( !isset( $wgNamespaceContentModels[$ns] ) ||
) {
$wikitextNS = $ns;
return $wikitextNS;
}
}
throw new MWException(
"No namespace defaults to wikitext!" );
}
# This check may also protect against code injection in
# case of broken installations.
$haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
if ( !$haveDiff3 ) {
$this->markTestSkipped( "Skip test, since diff3 is not configured" );
}
}
static $haveGzip;
if ( $haveGzip === null ) {
}
if ( !$haveGzip ) {
$this->markTestSkipped( "Skip test, requires the gzip utility in PATH" );
}
return $haveGzip;
}
$loaded = extension_loaded( $extName );
if ( !$loaded ) {
$this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." );
}
return $loaded;
}
protected function assertException( $code, $expected =
'Exception', $message =
'' ) {
$pokemons = null;
try {
call_user_func( $code );
} catch ( Exception $pokemons ) {
}
if ( $message === '' ) {
$message = 'An exception of type "' . $expected . '" should have been thrown';
}
$this->assertInstanceOf( $expected, $pokemons, $message );
}
$html =
'<!DOCTYPE html><html><head><title>test</title></head><body>' .
$html .
'</body></html>';
}
$this->markTestSkipped( 'Tidy extension not installed' );
}
$errorBuffer = '';
$allErrors = preg_split( '/[\r\n]+/', $errorBuffer );
$errors = preg_grep(
'/^(.*Warning: (trimming empty|.* lacks ".*?" attribute).*|\s*)$/m',
$allErrors, PREG_GREP_INVERT
);
$this->assertEmpty( $errors, implode( "\n", $errors ) );
}
}