Switch testApiLoginGoodPass to use doApiRequest
authorSam Reed <reedy@users.mediawiki.org>
Fri, 1 Oct 2010 21:50:52 +0000 (21:50 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Fri, 1 Oct 2010 21:50:52 +0000 (21:50 +0000)
Submitting for IRC sanity check :D

maintenance/tests/phpunit/includes/api/ApiTest.php

index b520032..178e6ed 100644 (file)
@@ -124,36 +124,37 @@ class ApiTest extends ApiTestSetup {
                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() {
@@ -192,7 +193,6 @@ class ApiTest extends ApiTestSetup {
                $this->assertNotEquals( '', $serializedCookie );
                $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/', $serializedCookie );
 
-
                return $cj;
        }