wiki.techinc.nl/tests/phpunit/maintenance/getSlaveServerTest.php
Platonides 26aade100d Remove more register_globals remote includes in the tests
backupPrefetchTest.php, backupTextPassTest.php, fetchTextTest.php
and getSlaveServerTest.php

Change-Id: Ie309f4377e4199d80c0f45dc761d3a14b8d00ec2
2012-06-11 15:29:52 +02:00

69 lines
1.7 KiB
PHP

<?php
require_once dirname( __FILE__ ) . "/../../../maintenance/getSlaveServer.php";
/**
* Tests for getSlaveServer
*
* @group Database
*/
class GetSlaveServerTest extends MediaWikiTestCase {
/**
* Yields a regular expression that matches a good DB server name
*
* It matches IPs or hostnames, both optionally followed by a
* port specification
*
* @return String the regular expression
*/
private function getServerRE() {
if ( $this->db->getType() === 'sqlite' ) {
// for SQLite, only the empty string is a good server name
return '';
}
$octet = '([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])';
$ip = "(($octet\.){3}$octet)";
$label = '([a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)';
$hostname = "($label(\.$label)*)";
return "($ip|$hostname)(:[0-9]{1,5})?";
}
function testPlain() {
$gss = new GetSlaveServer();
$gss->execute();
$this->expectOutputRegex( "/^" . self::getServerRE() . "\n$/D" );
}
function testXmlDumpsBackupUseCase() {
global $wgDBprefix;
global $argv;
$argv = array( null, "--globals" );
$gss = new GetSlaveServer();
$gss->loadParamsAndArgs();
$gss->execute();
$gss->globals();
// The main answer
$output = $this->getActualOutput();
$firstLineEndPos = strpos( $output,"\n");
if ( $firstLineEndPos === FALSE ) {
$this->fail( "Could not find end of first line of output" );
}
$firstLine = substr( $output, 0 , $firstLineEndPos );
$this->assertRegExp( "/^" . self::getServerRE() . "$/D",
$firstLine, "DB Server" );
// xmldumps-backup relies on the wgDBprefix in the output.
$this->expectOutputRegex( "/^[[:space:]]*\[wgDBprefix\][[:space:]]*=> "
. $wgDBprefix . "$/m" );
}
}