3 require_once __DIR__
. "/../../../maintenance/getSlaveServer.php";
6 * Tests for getSlaveServer
9 * @covers GetSlaveServer
11 class GetSlaveServerTest
extends MediaWikiTestCase
{
14 * Yields a regular expression that matches a good DB server name
16 * It matches IPs or hostnames, both optionally followed by a
19 * @return string The regular expression
21 private function getServerRE() {
22 if ( $this->db
->getType() === 'sqlite' ) {
23 // for SQLite, only the empty string is a good server name
27 $octet = '([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])';
28 $ip = "(($octet\.){3}$octet)";
30 $label = '([a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)';
31 $hostname = "($label(\.$label)*)";
33 return "($ip|$hostname)(:[0-9]{1,5})?";
36 function testPlain() {
37 $gss = new GetSlaveServer();
40 $this->expectOutputRegex( "/^" . self
::getServerRE() . "\n$/D" );
43 function testXmlDumpsBackupUseCase() {
47 $argv = array( null, "--globals" );
49 $gss = new GetSlaveServer();
50 $gss->loadParamsAndArgs();
55 $output = $this->getActualOutput();
56 $firstLineEndPos = strpos( $output, "\n" );
57 if ( $firstLineEndPos === false ) {
58 $this->fail( "Could not find end of first line of output" );
60 $firstLine = substr( $output, 0, $firstLineEndPos );
61 $this->assertRegExp( "/^" . self
::getServerRE() . "$/D",
62 $firstLine, "DB Server" );
64 // xmldumps-backup relies on the wgDBprefix in the output.
65 $this->expectOutputRegex( "/^[[:space:]]*\[wgDBprefix\][[:space:]]*=> "
66 . $wgDBprefix . "$/m" );