Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / maintenance / getSlaveServerTest.php
blob165dc55158cbc88ce67d5ab252e0af9cf1931cbd
1 <?php
3 require_once __DIR__ . "/../../../maintenance/getSlaveServer.php";
5 /**
6 * Tests for getSlaveServer
8 * @group Database
9 * @covers GetSlaveServer
11 class GetSlaveServerTest extends MediaWikiTestCase {
13 /**
14 * Yields a regular expression that matches a good DB server name
16 * It matches IPs or hostnames, both optionally followed by a
17 * port specification
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
24 return '';
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();
38 $gss->execute();
40 $this->expectOutputRegex( "/^" . self::getServerRE() . "\n$/D" );
43 function testXmlDumpsBackupUseCase() {
44 global $wgDBprefix;
46 global $argv;
47 $argv = array( null, "--globals" );
49 $gss = new GetSlaveServer();
50 $gss->loadParamsAndArgs();
51 $gss->execute();
52 $gss->globals();
54 // The main answer
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" );