3 require_once __DIR__
. "/../../../maintenance/getSlaveServer.php";
6 * Tests for getSlaveServer
10 class GetSlaveServerTest
extends MediaWikiTestCase
{
13 * Yields a regular expression that matches a good DB server name
15 * It matches IPs or hostnames, both optionally followed by a
18 * @return String the regular expression
20 private function getServerRE() {
21 if ( $this->db
->getType() === 'sqlite' ) {
22 // for SQLite, only the empty string is a good server name
26 $octet = '([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])';
27 $ip = "(($octet\.){3}$octet)";
29 $label = '([a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)';
30 $hostname = "($label(\.$label)*)";
32 return "($ip|$hostname)(:[0-9]{1,5})?";
35 function testPlain() {
36 $gss = new GetSlaveServer();
39 $this->expectOutputRegex( "/^" . self
::getServerRE() . "\n$/D" );
42 function testXmlDumpsBackupUseCase() {
46 $argv = array( null, "--globals" );
48 $gss = new GetSlaveServer();
49 $gss->loadParamsAndArgs();
54 $output = $this->getActualOutput();
55 $firstLineEndPos = strpos( $output, "\n" );
56 if ( $firstLineEndPos === false ) {
57 $this->fail( "Could not find end of first line of output" );
59 $firstLine = substr( $output, 0, $firstLineEndPos );
60 $this->assertRegExp( "/^" . self
::getServerRE() . "$/D",
61 $firstLine, "DB Server" );
63 // xmldumps-backup relies on the wgDBprefix in the output.
64 $this->expectOutputRegex( "/^[[:space:]]*\[wgDBprefix\][[:space:]]*=> "
65 . $wgDBprefix . "$/m" );