Localisation updates from http://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / getSlaveServerTest.php
blob29e7fe62f8c9f181a694b89be057f404a0fdd48b
1 <?php
2 global $IP;
3 require_once( "$IP/maintenance/getSlaveServer.php" );
5 /**
6 * Tests for getSlaveServer
8 * @group Database
9 */
10 class GetSlaveServerTest extends MediaWikiTestCase {
12 /**
13 * Yields a regular expression that matches a good DB server name
15 * It matches IPs or hostnames, both optionally followed by a
16 * port specification
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
23 return '';
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();
37 $gss->execute();
39 $this->expectOutputRegex( "/^" . self::getServerRE() . "\n$/D" );
42 function testXmlDumpsBackupUseCase() {
43 global $wgDBprefix;
45 global $argv;
46 $argv = array( null, "--globals" );
48 $gss = new GetSlaveServer();
49 $gss->loadParamsAndArgs();
50 $gss->execute();
51 $gss->globals();
53 // The main answer
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" );