$sxe = simplexml_load_string( $resp );
$this->assertNotType( "bool", $sxe );
$this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
- $a = $sxe->login[0]->attributes()->result;
- $this->assertEquals( ' result="WrongPass"', $a->asXML() );
+ $a = $sxe->login[0]->attributes()->result[0];
+ $this->assertEquals( ' result="NeedToken"', $a->asXML() );
+
+ $token = (string)$sxe->login[0]->attributes()->token;
+
+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
+ array( "postData" => array(
+ "lgtoken" => $token,
+ "lgname" => self::$userName,
+ "lgpassword" => "bad" ) ) );
+
+
+ $sxe = simplexml_load_string( $resp );
+ $this->assertNotType( "bool", $sxe );
+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
+ $a = $sxe->login[0]->attributes()->result[0];
+
+ $this->assertEquals( ' result="NeedToken"', $a->asXML() );
}
function testApiLoginGoodPass() {
$this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
'be set in LocalSettings.php');
}
- $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
- array( "postData" => array(
- "lgname" => self::$userName,
- "lgpassword" => self::$passWord ) ) );
+ $req = HttpRequest::factory(self::$apiUrl . "?action=login&format=xml",
+ array( "method" => "POST",
+ "postData" => array(
+ "lgname" => self::$userName,
+ "lgpassword" => self::$passWord ) ) );
+ $req->execute();
+
libxml_use_internal_errors( true );
- $sxe = simplexml_load_string( $resp );
+ $sxe = simplexml_load_string( $req->getContent() );
$this->assertNotType( "bool", $sxe );
$this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
- $a = $sxe->login[0]->attributes()->result;
+
+ $a = $sxe->login[0]->attributes()->result[0];
+ $this->assertEquals( ' result="NeedToken"', $a->asXML() );
+ $token = (string)$sxe->login[0]->attributes()->token;
+
+ $req->setData(array(
+ "lgtoken" => $token,
+ "lgname" => self::$userName,
+ "lgpassword" => self::$passWord ) );
+ $req->execute();
+
+ $sxe = simplexml_load_string( $req->getContent() );
+
+ $this->assertNotType( "bool", $sxe );
+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
+ $a = $sxe->login[0]->attributes()->result[0];
+
$this->assertEquals( ' result="Success"', $a->asXML() );
}
$this->markTestIncomplete('This test needs $wgServerName and $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 = HttpRequest::factory(self::$apiUrl . "?action=login&format=xml",
+ array( "method" => "POST",
+ "postData" => array(
+ "lgname" => self::$userName,
+ "lgpassword" => self::$passWord ) ) );
$req->execute();
+
+ libxml_use_internal_errors( true );
+ $sxe = simplexml_load_string( $req->getContent() );
+ $this->assertNotType( "bool", $sxe );
+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
+
+ $a = $sxe->login[0]->attributes()->result[0];
+ $this->assertEquals( ' result="NeedToken"', $a->asXML() );
+ $token = (string)$sxe->login[0]->attributes()->token;
+
+ $req->setData(array(
+ "lgtoken" => $token,
+ "lgname" => self::$userName,
+ "lgpassword" => self::$passWord ) );
+ $req->execute();
+
$cj = $req->getCookieJar();
$this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/',
$cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );