MediaWiki
REL1_22
|
00001 <?php 00002 00003 require_once __DIR__ . "/../../../maintenance/getSlaveServer.php"; 00004 00010 class GetSlaveServerTest extends MediaWikiTestCase { 00011 00020 private function getServerRE() { 00021 if ( $this->db->getType() === 'sqlite' ) { 00022 // for SQLite, only the empty string is a good server name 00023 return ''; 00024 } 00025 00026 $octet = '([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'; 00027 $ip = "(($octet\.){3}$octet)"; 00028 00029 $label = '([a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)'; 00030 $hostname = "($label(\.$label)*)"; 00031 00032 return "($ip|$hostname)(:[0-9]{1,5})?"; 00033 } 00034 00035 function testPlain() { 00036 $gss = new GetSlaveServer(); 00037 $gss->execute(); 00038 00039 $this->expectOutputRegex( "/^" . self::getServerRE() . "\n$/D" ); 00040 } 00041 00042 function testXmlDumpsBackupUseCase() { 00043 global $wgDBprefix; 00044 00045 global $argv; 00046 $argv = array( null, "--globals" ); 00047 00048 $gss = new GetSlaveServer(); 00049 $gss->loadParamsAndArgs(); 00050 $gss->execute(); 00051 $gss->globals(); 00052 00053 // The main answer 00054 $output = $this->getActualOutput(); 00055 $firstLineEndPos = strpos( $output, "\n" ); 00056 if ( $firstLineEndPos === false ) { 00057 $this->fail( "Could not find end of first line of output" ); 00058 } 00059 $firstLine = substr( $output, 0, $firstLineEndPos ); 00060 $this->assertRegExp( "/^" . self::getServerRE() . "$/D", 00061 $firstLine, "DB Server" ); 00062 00063 // xmldumps-backup relies on the wgDBprefix in the output. 00064 $this->expectOutputRegex( "/^[[:space:]]*\[wgDBprefix\][[:space:]]*=> " 00065 . $wgDBprefix . "$/m" ); 00066 } 00067 }