Follow-up r61938: also port SearchUpdate test
[lhc/web/wiklou.git] / tests / MediaWikiAPITest.php
1 <?php
2
3 require_once( "MediaWikiAPI_TestCase.php" );
4
5 class MediaWikiAPITest extends MediaWikiAPI_TestCase {
6
7 function setup() {
8 parent::setup();
9 }
10
11 function testApi() {
12 /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
13 $resp = Http::get( self::$apiUrl . "?format=xml" );
14
15 libxml_use_internal_errors( true );
16 $sxe = simplexml_load_string( $resp );
17 $this->assertNotType( "bool", $sxe );
18 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
19 }
20
21 function testApiLoginNoName() {
22 $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
23 array( "postData" => array(
24 "lgname" => "",
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() );
32 }
33
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() );
45 }
46
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() );
58 }
59
60 function testApiGotCookie() {
61 global $wgScriptPath, $wgServerName;
62
63 $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
64 array( "method" => "POST",
65 "postData" => array(
66 "lgname" => self::$userName,
67 "lgpassword" => self::$passWord ) ) );
68 $req->execute();
69 $cj = $req->getCookieJar();
70
71 $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/',
72 $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
73 }
74 }