Просмотр исходного кода

[Http][Client] Add tests for OPTIONS requests

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

+ 47 - 0
tests/Zend/Http/Client/CommonHttpTests.php

@@ -256,6 +256,36 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
     }
 
     /**
+     * Test we can properly send OPTIONS parameters with
+     * application/x-www-form-urlencoded content type
+     *
+     * @dataProvider parameterArrayProvider
+     */
+    public function testOptionsDataUrlEncoded($params)
+    {
+        $this->client->setUri($this->baseuri . 'testOptionsData.php');
+        $this->client->setEncType(Zend_Http_Client::ENC_URLENCODED);
+        $this->client->setParameterPost($params);
+        $res = $this->client->request('OPTIONS');
+        $this->assertEquals(serialize($params), $res->getBody(), "OPTIONS data integrity test failed");
+    }
+
+    /**
+     * Test we can properly send OPTIONS parameters without
+     * content type, relying on default content type (urlencoded)
+     *
+     * @dataProvider parameterArrayProvider
+     */
+    public function testOptionsDataDefault($params)
+    {
+        $this->client->setUri($this->baseuri . 'testOptionsData.php');
+        // note that no content type is set
+        $this->client->setParameterPost($params);
+        $res = $this->client->request('OPTIONS');
+        $this->assertEquals(serialize($params), $res->getBody(), "OPTIONS data integrity test failed for default content-type");
+    }
+
+    /**
      * Test we can properly send parameters with
      * application/x-www-form-urlencoded content type
      *
@@ -320,6 +350,23 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
     }
 
     /**
+     * Test we can properly send OPTIONS parameters with
+     * multipart/form-data content type
+     *
+     * @dataProvider parameterArrayProvider
+     */
+    public function testOptionsDataMultipart($params)
+    {
+        $this->client->setUri($this->baseuri . 'testRawOptionsData.php');
+        $this->client->setParameterPost($params);
+        $this->client->setMethod(Zend_Http_Client::OPTIONS);
+        $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
      *

+ 25 - 0
tests/Zend/Http/Client/_files/testOptionsData.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/testRawOptionsData.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');