Browse Source

[ZF-11598] Zend_Http_Client

- Fixed, return of the adapter after constructor.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24261 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon 14 years ago
parent
commit
ba27ccaa04
2 changed files with 32 additions and 19 deletions
  1. 13 9
      library/Zend/Http/Client.php
  2. 19 10
      tests/Zend/Http/Client/StaticTest.php

+ 13 - 9
library/Zend/Http/Client.php

@@ -101,7 +101,7 @@ class Zend_Http_Client
      */
     const ENC_URLENCODED = 'application/x-www-form-urlencoded';
     const ENC_FORMDATA   = 'multipart/form-data';
-    
+
     /**
      * Value types for Body key/value pairs
      */
@@ -207,14 +207,14 @@ class Zend_Http_Client
      * @var array
      */
     protected $files = array();
-    
+
     /**
      * Ordered list of keys from key/value pair data to include in body
-     * 
+     *
      * An associative array, where each element is of the format:
      *   '<field name>' => VTYPE_SCALAR | VTYPE_FILE
-     * 
-     * @var array 
+     *
+     * @var array
      */
     protected $body_field_order = array();
 
@@ -740,7 +740,7 @@ class Zend_Http_Client
             'ctype'    => $ctype,
             'data'     => $data
         );
-        
+
         $this->body_field_order[$formname] = self::VTYPE_FILE;
 
         return $this;
@@ -807,7 +807,7 @@ class Zend_Http_Client
         $this->files         = array();
         $this->raw_post_data = null;
         $this->enctype       = null;
-        
+
         if($clearAll) {
             $this->headers = array();
             $this->last_request = null;
@@ -891,6 +891,10 @@ class Zend_Http_Client
      */
     public function getAdapter()
     {
+        if (null === $this->adapter) {
+            $this->setAdapter($this->config['adapter']);
+        }
+
         return $this->adapter;
     }
 
@@ -1047,7 +1051,7 @@ class Zend_Http_Client
                 // Avoid problems with buggy servers that add whitespace at the
                 // end of some headers (See ZF-11283)
                 $location = trim($location);
-                
+
                 // Check whether we send the exact same request again, or drop the parameters
                 // and send a GET request
                 if ($response->getStatus() == 303 ||
@@ -1232,7 +1236,7 @@ class Zend_Http_Client
                     foreach ($this->files as $key=>$fdata ) {
                         $fileIndexMap[$fdata['formname']] = $key;
                     }
-                    
+
                     // Encode all files and POST vars in the order they were given
                     foreach ($this->body_field_order as $fieldName=>$fieldType) {
                         switch ($fieldType) {

+ 19 - 10
tests/Zend/Http/Client/StaticTest.php

@@ -557,7 +557,7 @@ class Zend_Http_Client_StaticTest extends PHPUnit_Framework_TestCase
         $this->_client->setUri('http://example.com');
         $this->_client->setFileUpload('testFile.name', 'testFile', 'TESTDATA12345', 'text/plain');
         $this->_client->request('POST');
-        
+
         $expectedLines = file(dirname(__FILE__) . '/_files/ZF4236-fileuploadrequest.txt');
         $gotLines = explode("\n", trim($this->_client->getLastRequest()));
 
@@ -570,7 +570,7 @@ class Zend_Http_Client_StaticTest extends PHPUnit_Framework_TestCase
             $this->assertRegExp("/^$expected$/", $got);
         }
     }
-    
+
     /**
      * @group ZF-4236
      */
@@ -582,7 +582,7 @@ class Zend_Http_Client_StaticTest extends PHPUnit_Framework_TestCase
         $this->_client->setFileUpload('testFile.name', 'testFile', 'TESTDATA12345', 'text/plain');
         $this->_client->setParameterPost('testLast', 'bar');
         $this->_client->request('POST');
-        
+
         $expectedLines = file(dirname(__FILE__) . '/_files/ZF4236-clientbodyretainsfieldordering.txt');
         $gotLines = explode("\n", trim($this->_client->getLastRequest()));
 
@@ -675,10 +675,10 @@ class Zend_Http_Client_StaticTest extends PHPUnit_Framework_TestCase
 			return;
 		}
     }
-    
+
 	/**
      * Test that we can handle trailing space in location header
-     * 
+     *
      * @group ZF-11283
      * @link http://framework.zend.com/issues/browse/ZF-11283
      */
@@ -686,13 +686,13 @@ class Zend_Http_Client_StaticTest extends PHPUnit_Framework_TestCase
     {
         $this->_client->setUri('http://example.com/');
         $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
-        
+
         $adapter = $this->_client->getAdapter(); /* @var $adapter Zend_Http_Client_Adapter_Test */
-        
+
         $adapter->setResponse(<<<RESPONSE
 HTTP/1.1 302 Redirect
 Content-Type: text/html; charset=UTF-8
-Location: /test   
+Location: /test
 Server: Microsoft-IIS/7.0
 Date: Tue, 19 Apr 2011 11:23:48 GMT
 
@@ -700,13 +700,22 @@ RESPONSE
         );
 
         $res = $this->_client->request('GET');
-        
+
         $lastUri = $this->_client->getUri();
-        
+
         $this->assertEquals("/test", $lastUri->getPath());
     }
 
     /**
+     * @group ZF-11598
+     */
+    public function testAdapter()
+    {
+        $client = new Zend_Http_Client(null, array('adapter' => 'Zend_Http_Client_Adapter_Test'));
+        $this->assertTrue($client->getAdapter() instanceof Zend_Http_Client_Adapter_Test);
+    }
+
+    /**
      * Data providers
      */