if ( !isset( $wgServer ) ) {
$this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' );
}
- $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
- array( "method" => "POST",
- "postData" => array(
- "lgname" => self::$userName,
- "lgpassword" => self::$passWord ) ) );
- $req->execute();
+
+ $ret = $this->doApiRequest( array(
+ "action" => "login",
+ "lgname" => self::$userName,
+ "lgpassword" => self::$passWord,
+ )
+ );
libxml_use_internal_errors( true );
- $sxe = simplexml_load_string( $req->getContent() );
- $this->assertNotType( "bool", $sxe );
- $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
- $this->assertNotType( "null", $sxe->login[0] );
+ $result = $ret[0];
+ $this->assertNotType( "bool", $result );
+ $this->assertNotType( "null", $result["login"] );
- $a = $sxe->login[0]->attributes()->result[0];
- $this->assertEquals( ' result="NeedToken"', $a->asXML() );
- $token = (string)$sxe->login[0]->attributes()->token;
+ $a = $result["login"]["result"];
+ $this->assertEquals( "NeedToken", $a );
+ $token = $result["login"]["token"];
- $req->setData( array(
+ $ret = $this->doApiRequest( array(
+ "action" => "login",
"lgtoken" => $token,
"lgname" => self::$userName,
- "lgpassword" => self::$passWord ) );
- $req->execute();
+ "lgpassword" => self::$passWord,
+ )
+ );
- $sxe = simplexml_load_string( $req->getContent() );
+ $result = $ret[0];
- $this->assertNotType( "bool", $sxe );
- $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
- $a = $sxe->login[0]->attributes()->result[0];
+ $this->assertNotType( "bool", $result );
+ $a = $result["login"]["result"];
- $this->assertEquals( ' result="Success"', $a->asXML() );
+ $this->assertEquals( "Success", $a );
}
function testApiGotCookie() {
$this->assertNotEquals( '', $serializedCookie );
$this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/', $serializedCookie );
-
return $cj;
}