Move doApiRequest() up a level so ApiTest can use it as well. Fix first two tests...
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 29 Sep 2010 18:19:03 +0000 (18:19 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 29 Sep 2010 18:19:03 +0000 (18:19 +0000)
maintenance/tests/phpunit/includes/UploadFromUrlTest.php
maintenance/tests/phpunit/includes/api/ApiSetup.php
maintenance/tests/phpunit/includes/api/ApiTest.php
maintenance/tests/phpunit/includes/api/ApiWatchTest.php

index 7bcb5fb..c636010 100644 (file)
@@ -25,7 +25,7 @@ class UploadFromUrlTest extends ApiTestSetup {
                }
        }
 
-       protected function doApiRequest( $params ) {
+       protected function doApiRequest( $params, $unused = null ) {
                $sessionId = session_id();
                session_write_close();
                
index 5e108d2..88960db 100644 (file)
@@ -18,6 +18,20 @@ abstract class ApiTestSetup extends PHPUnit_Framework_TestCase {
                self::setupUser();
        }
 
+       protected function doApiRequest( $params, $data = null ) {
+               $_SESSION = isset( $data[2] ) ? $data[2] : array();
+
+               $req = new FauxRequest( $params, true, $_SESSION );
+               $module = new ApiMain( $req, true );
+               $module->execute();
+
+               $data[0] = $module->getResultData();
+               $data[1] = $req;
+               $data[2] = $_SESSION;
+
+               return $data;
+       }
+
        static function setupUser() {
                if ( self::$user == NULL ) {
                        self::$userName = "Useruser";
index 9ee931f..b520032 100644 (file)
@@ -53,14 +53,20 @@ class ApiTest extends ApiTestSetup {
                                                                                                           "enablechunks" => true ), "filename", "enablechunks" ) );
        }
 
+       /**
+        * Test that the API will accept a FauxRequest and execute. The help action
+        * (default) throws a UsageException. Just validate we're getting proper XML
+        *
+        * @expectedException UsageException
+        */
        function testApi() {
-               global $wgServer;
-
-               if ( !isset( $wgServer ) ) {
-                       $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' );
-               }
-               /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
-               $resp = Http::get( self::$apiUrl . "?format=xml" );
+               $api = new ApiMain(
+                       new FauxRequest( array( 'action' => 'help', 'format' => 'xml' ) )
+               );
+               $api->execute();
+               $api->getPrinter()->setBufferResult( true );
+               $api->printResult( false );
+               $resp = $api->getPrinter()->getBuffer();
 
                libxml_use_internal_errors( true );
                $sxe = simplexml_load_string( $resp );
@@ -68,22 +74,14 @@ class ApiTest extends ApiTestSetup {
                $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
        }
 
+       /**
+        * Test result of attempted login with an empty username
+        */
        function testApiLoginNoName() {
-               global $wgServer;
-
-               if ( !isset( $wgServer ) ) {
-                       $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' );
-               }
-               $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
-                                                  array( "postData" => array(
-                                                                        "lgname" => "",
-                                                                        "lgpassword" => self::$passWord ) ) );
-               libxml_use_internal_errors( true );
-               $sxe = simplexml_load_string( $resp );
-               $this->assertNotType( "bool", $sxe );
-               $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
-               $a = $sxe->login[0]->attributes()->result;
-               $this->assertEquals( ' result="NoName"', $a->asXML() );
+               $data = $this->doApiRequest( array( 'action' => 'login',
+                       'lgname' => '', 'lgpassword' => self::$passWord
+               ) );
+               $this->assertEquals( 'NoName', $data[0]['login']['result'] );
        }
 
        function testApiLoginBadPass() {
index 7477a89..032e244 100644 (file)
@@ -8,20 +8,6 @@ class ApiWatchTest extends ApiTestSetup {
                parent::setUp();
        }
 
-       function doApiRequest( $params, $data = null ) {
-               $_SESSION = isset( $data[2] ) ? $data[2] : array();
-
-               $req = new FauxRequest( $params, true, $_SESSION );
-               $module = new ApiMain( $req, true );
-               $module->execute();
-
-               $data[0] = $module->getResultData();
-               $data[1] = $req;
-               $data[2] = $_SESSION;
-
-               return $data;
-       }
-
        function testLogin() {
                $data = $this->doApiRequest( array(
                        'action' => 'login',