3 require_once("MediaWikiAPI_TestCase.php");
5 class MediaWikiAPITest
extends MediaWikiAPI_TestCase
{
12 /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
13 $resp = Http
::get(self
::$apiUrl."?format=xml");
15 libxml_use_internal_errors(true);
16 $sxe = simplexml_load_string($resp);
17 $this->assertNotType("bool", $sxe);
18 $this->assertThat($sxe, $this->isInstanceOf("SimpleXMLElement"));
21 function testApiLoginNoName() {
22 $resp = Http
::post(self
::$apiUrl."?action=login&format=xml",
23 array("postData" => array(
25 "lgpassword" => self
::$passWord)));
26 libxml_use_internal_errors(true);
27 $sxe = simplexml_load_string($resp);
28 $this->assertNotType("bool", $sxe);
29 $this->assertThat($sxe, $this->isInstanceOf("SimpleXMLElement"));
30 $a = $sxe->login
[0]->attributes()->result
;
31 $this->assertEquals( ' result="NoName"', $a->asXML() );
34 function testApiLoginBadPass() {
35 $resp = Http
::post(self
::$apiUrl."?action=login&format=xml",
36 array("postData" => array(
37 "lgname" => self
::$userName,
38 "lgpassword" => "bad")));
39 libxml_use_internal_errors(true);
40 $sxe = simplexml_load_string($resp);
41 $this->assertNotType("bool", $sxe);
42 $this->assertThat($sxe, $this->isInstanceOf("SimpleXMLElement"));
43 $a = $sxe->login
[0]->attributes()->result
;
44 $this->assertEquals( ' result="WrongPass"', $a->asXML() );
47 function testApiLoginGoodPass() {
48 $resp = Http
::post(self
::$apiUrl."?action=login&format=xml",
49 array("postData" => array(
50 "lgname" => self
::$userName,
51 "lgpassword" => self
::$passWord)));
52 libxml_use_internal_errors(true);
53 $sxe = simplexml_load_string($resp);
54 $this->assertNotType("bool", $sxe);
55 $this->assertThat($sxe, $this->isInstanceOf("SimpleXMLElement"));
56 $a = $sxe->login
[0]->attributes()->result
;
57 $this->assertEquals( ' result="Success"', $a->asXML() );
60 function testApiGotCookie() {
61 global $wgScriptPath, $wgServerName;
63 $req = HttpRequest
::factory(self
::$apiUrl."?action=login&format=xml",
64 array("method" => "POST",
66 "lgname" => self
::$userName,
67 "lgpassword" => self
::$passWord)));
69 $cj = $req->getCookieJar();
71 $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName='.self
::$userName.'; .*Token=/',
72 $cj->serializeToHttpRequest($wgScriptPath, $wgServerName) );