Merge "(bug 17602) fix Monobook action tabs not quite touching the page body"
[lhc/web/wiklou.git] / tests / phpunit / maintenance / getSlaveServerTest.php
1 <?php
2
3 require_once __DIR__ . "/../../../maintenance/getSlaveServer.php";
4
5 /**
6 * Tests for getSlaveServer
7 *
8 * @group Database
9 */
10 class GetSlaveServerTest extends MediaWikiTestCase {
11
12 /**
13 * Yields a regular expression that matches a good DB server name
14 *
15 * It matches IPs or hostnames, both optionally followed by a
16 * port specification
17 *
18 * @return String the regular expression
19 */
20 private function getServerRE() {
21 if ( $this->db->getType() === 'sqlite' ) {
22 // for SQLite, only the empty string is a good server name
23 return '';
24 }
25
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)";
28
29 $label = '([a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)';
30 $hostname = "($label(\.$label)*)";
31
32 return "($ip|$hostname)(:[0-9]{1,5})?";
33 }
34
35 function testPlain() {
36 $gss = new GetSlaveServer();
37 $gss->execute();
38
39 $this->expectOutputRegex( "/^" . self::getServerRE() . "\n$/D" );
40 }
41
42 function testXmlDumpsBackupUseCase() {
43 global $wgDBprefix;
44
45 global $argv;
46 $argv = array( null, "--globals" );
47
48 $gss = new GetSlaveServer();
49 $gss->loadParamsAndArgs();
50 $gss->execute();
51 $gss->globals();
52
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" );
58 }
59 $firstLine = substr( $output, 0, $firstLineEndPos );
60 $this->assertRegExp( "/^" . self::getServerRE() . "$/D",
61 $firstLine, "DB Server" );
62
63 // xmldumps-backup relies on the wgDBprefix in the output.
64 $this->expectOutputRegex( "/^[[:space:]]*\[wgDBprefix\][[:space:]]*=> "
65 . $wgDBprefix . "$/m" );
66 }
67 }