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