Eric GELOEN 11 лет назад
Родитель
Сommit
fff98e44ef

+ 69 - 22
tests/Zend/Http/Client/CommonHttpTests.php

@@ -134,7 +134,7 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
      */
     public function testSimpleRequests()
     {
-        $methods = array('GET', 'POST', 'OPTIONS', 'PUT', 'DELETE');
+        $methods = array('GET', 'POST', 'OPTIONS', 'PUT', 'PATCH', 'DELETE');
 
         foreach ($methods as $method) {
             $res = $this->client->request($method);
@@ -194,7 +194,7 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $res = $this->client->request('POST');
         $this->assertEquals(serialize($params), $res->getBody(), "POST data integrity test failed");
     }
-    
+
     /**
      * Test we can properly send PUT parameters with
      * application/x-www-form-urlencoded content type
@@ -209,7 +209,7 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $res = $this->client->request('PUT');
         $this->assertEquals(serialize($params), $res->getBody(), "PUT data integrity test failed");
     }
-    
+
     /**
      * Test we can properly send PUT parameters without
      * content type, relying on default content type (urlencoded)
@@ -224,7 +224,37 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $res = $this->client->request('PUT');
         $this->assertEquals(serialize($params), $res->getBody(), "PUT data integrity test failed for default content-type");
     }
-    
+
+    /**
+     * Test we can properly send PATCH parameters with
+     * application/x-www-form-urlencoded content type
+     *
+     * @dataProvider parameterArrayProvider
+     */
+    public function testPatchDataUrlEncoded($params)
+    {
+        $this->client->setUri($this->baseuri . 'testPatchData.php');
+        $this->client->setEncType(Zend_Http_Client::ENC_URLENCODED);
+        $this->client->setParameterPost($params);
+        $res = $this->client->request('PATCH');
+        $this->assertEquals(serialize($params), $res->getBody(), "PATCH data integrity test failed");
+    }
+
+    /**
+     * Test we can properly send PATCH parameters without
+     * content type, relying on default content type (urlencoded)
+     *
+     * @dataProvider parameterArrayProvider
+     */
+    public function testPatchDataDefault($params)
+    {
+        $this->client->setUri($this->baseuri . 'testPatchData.php');
+        // note that no content type is set
+        $this->client->setParameterPost($params);
+        $res = $this->client->request('PATCH');
+        $this->assertEquals(serialize($params), $res->getBody(), "PATCH data integrity test failed for default content-type");
+    }
+
     /**
      * Test we can properly send parameters with
      * application/x-www-form-urlencoded content type
@@ -254,7 +284,7 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $res = $this->client->request('POST');
         $this->assertEquals(serialize($params), $res->getBody(), "POST data integrity test failed");
     }
-    
+
     /**
      * Test we can properly send PUT parameters with
      * multipart/form-data content type
@@ -271,35 +301,52 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $responseText = $response->getBody();
         $this->_checkPresence($responseText, $params);
     }
-    
+
+    /**
+     * Test we can properly send PATCH parameters with
+     * multipart/form-data content type
+     *
+     * @dataProvider parameterArrayProvider
+     */
+    public function testPatchDataMultipart($params)
+    {
+        $this->client->setUri($this->baseuri . 'testRawPatchData.php');
+        $this->client->setParameterPost($params);
+        $this->client->setMethod(Zend_Http_Client::PATCH);
+        $this->client->setEncType(Zend_Http_Client::ENC_FORMDATA);
+        $response = $this->client->request();
+        $responseText = $response->getBody();
+        $this->_checkPresence($responseText, $params);
+    }
+
     /**
      * Checks the presence of keys (non-numeric only) and values
      * in the raw form data reponse for a PUT or DELETE request recursively
-     * 
+     *
      * An example response (I do not know of a better way to check it):
      * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
      * Content-Disposition: form-data; name="quest"
-     * 
+     *
      * To seek the holy grail
      * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
      * Content-Disposition: form-data; name="YourMother"
-     * 
+     *
      * Was a hamster
      * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
      * Content-Disposition: form-data; name="specialChars"
-     * 
+     *
      * <>$+ &?=[]^%
      * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
      * Content-Disposition: form-data; name="array[]"
-     * 
+     *
      * firstItem
      * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
      * Content-Disposition: form-data; name="array[]"
-     * 
+     *
      * secondItem
      * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
      * Content-Disposition: form-data; name="array[]"
-     * 
+     *
      * 3rdItem
      * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828--
      * @param string $responseText
@@ -319,19 +366,19 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
                 if (!is_int($key)) {
                     $this->assertGreaterThan(
                         0,
-                        strpos($responseText, $key), 
+                        strpos($responseText, $key),
                         "key '$key' is missing from the reponse for raw multipart PUT or DELETE request"
                     );
                 }
                 $this->assertGreaterThan(
                     0,
-                    strpos($responseText, $value), 
+                    strpos($responseText, $value),
                     "value '$value' is missing from the reponse for raw multipart PUT or DELETE request"
                 );
             }
         }
     }
-    
+
     /**
      * Test we can properly send DELETE parameters with
      * multipart/form-data content type
@@ -360,12 +407,12 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $res = $this->client->setRawData($data, 'text/html')->request('POST');
         $this->assertEquals($data, $res->getBody(), 'Response body does not contain the expected data');
     }
-    
+
     /**
      * Test using raw HTTP PUT data
      *
      * @group ZF-11030
-     * 
+     *
      */
     public function testRawPutData()
     {
@@ -376,12 +423,12 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $response = $this->client->request();
         $this->assertEquals($data, $response->getBody(), 'Response body does not contain the expected data');
     }
-    
+
     /**
      * Test using raw HTTP DELETE data
      *
      * @group ZF-11030
-     * 
+     *
      */
     public function testRawDeleteData()
     {
@@ -1186,7 +1233,7 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $this->assertNotContains('Content-Type: text/plain', $request);
 
     }
-    
+
     /**
      * @group ZF-11598
      */
@@ -1196,7 +1243,7 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         $adapter = $client->getAdapter();
         $this->assertTrue(!empty($adapter));
     }
-    
+
     /**
      * Internal helpder function to get the contents of test files
      *

+ 25 - 0
tests/Zend/Http/Client/_files/testPatchData.php

@@ -0,0 +1,25 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Http
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id
+ */
+$variables = array();
+$data = file_get_contents('php://input');
+parse_str($data, $variables);
+echo serialize($variables);

+ 22 - 0
tests/Zend/Http/Client/_files/testRawPatchData.php

@@ -0,0 +1,22 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Http
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id
+ */
+echo file_get_contents('php://input');