Merge "Accessibility: Make the collapsible sidebar screen reader friendly"
[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 * @covers GetSlaveServer
10 */
11 class GetSlaveServerTest extends MediaWikiTestCase {
12
13 /**
14 * Yields a regular expression that matches a good DB server name
15 *
16 * It matches IPs or hostnames, both optionally followed by a
17 * port specification
18 *
19 * @return String the regular expression
20 */
21 private function getServerRE() {
22 if ( $this->db->getType() === 'sqlite' ) {
23 // for SQLite, only the empty string is a good server name
24 return '';
25 }
26
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)";
29
30 $label = '([a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)';
31 $hostname = "($label(\.$label)*)";
32
33 return "($ip|$hostname)(:[0-9]{1,5})?";
34 }
35
36 function testPlain() {
37 $gss = new GetSlaveServer();
38 $gss->execute();
39
40 $this->expectOutputRegex( "/^" . self::getServerRE() . "\n$/D" );
41 }
42
43 function testXmlDumpsBackupUseCase() {
44 global $wgDBprefix;
45
46 global $argv;
47 $argv = array( null, "--globals" );
48
49 $gss = new GetSlaveServer();
50 $gss->loadParamsAndArgs();
51 $gss->execute();
52 $gss->globals();
53
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" );
59 }
60 $firstLine = substr( $output, 0, $firstLineEndPos );
61 $this->assertRegExp( "/^" . self::getServerRE() . "$/D",
62 $firstLine, "DB Server" );
63
64 // xmldumps-backup relies on the wgDBprefix in the output.
65 $this->expectOutputRegex( "/^[[:space:]]*\[wgDBprefix\][[:space:]]*=> "
66 . $wgDBprefix . "$/m" );
67 }
68 }