http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73968

Revision: 73968
Author:   demon
Date:     2010-09-29 18:19:03 +0000 (Wed, 29 Sep 2010)

Log Message:
-----------
Move doApiRequest() up a level so ApiTest can use it as well. Fix first two 
tests to do internal FauxRequests rather than relying on an external HTTP 
connection

Modified Paths:
--------------
    trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
    trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php
    trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
    trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php

Modified: trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
===================================================================
--- trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php       
2010-09-29 18:18:07 UTC (rev 73967)
+++ trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php       
2010-09-29 18:19:03 UTC (rev 73968)
@@ -25,7 +25,7 @@
                }
        }
 
-       protected function doApiRequest( $params ) {
+       protected function doApiRequest( $params, $unused = null ) {
                $sessionId = session_id();
                session_write_close();
                

Modified: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php
===================================================================
--- trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php    
2010-09-29 18:18:07 UTC (rev 73967)
+++ trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php    
2010-09-29 18:19:03 UTC (rev 73968)
@@ -18,6 +18,20 @@
                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";

Modified: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
===================================================================
--- trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php     
2010-09-29 18:18:07 UTC (rev 73967)
+++ trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php     
2010-09-29 18:19:03 UTC (rev 73968)
@@ -53,37 +53,35 @@
                                                                                
                           "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;
+               $api = new ApiMain(
+                       new FauxRequest( array( 'action' => 'help', 'format' => 
'xml' ) )
+               );
+               $api->execute();
+               $api->getPrinter()->setBufferResult( true );
+               $api->printResult( false );
+               $resp = $api->getPrinter()->getBuffer();
 
-               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" );
-
                libxml_use_internal_errors( true );
                $sxe = simplexml_load_string( $resp );
                $this->assertNotType( "bool", $sxe );
                $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() {

Modified: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php
===================================================================
--- trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php        
2010-09-29 18:18:07 UTC (rev 73967)
+++ trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php        
2010-09-29 18:19:03 UTC (rev 73968)
@@ -8,20 +8,6 @@
                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',



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to