7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
16 * @package Zend_Controller
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: HttpTestCase.php 16541 2009-07-07 06:59:03Z bkarwin $
23 * @see Zend_Controller_Request_Http
25 require_once 'Zend/Controller/Request/Http.php';
28 * Zend_Controller_Request_HttpTestCase
30 * HTTP request object for use with Zend_Controller family.
32 * @uses Zend_Controller_Request_Http
33 * @package Zend_Controller
36 class Zend_Controller_Request_HttpTestCase
extends Zend_Controller_Request_Http
42 protected $_headers = array();
57 * Valid request method types
60 protected $_validMethodTypes = array(
72 * @return Zend_Controller_Request_HttpTestCase
74 public function clearQuery()
83 * @return Zend_Controller_Request_HttpTestCase
85 public function clearPost()
94 * @param string $content
95 * @return Zend_Controller_Request_HttpTestCase
97 public function setRawBody($content)
99 $this->_rawBody
= (string) $content;
106 * @return string|null
108 public function getRawBody()
110 return $this->_rawBody
;
114 * Clear raw POST body
116 * @return Zend_Controller_Request_HttpTestCase
118 public function clearRawBody()
120 $this->_rawBody
= null;
128 * @param mixed $value
129 * @return Zend_Controller_Request_HttpTestCase
131 public function setCookie($key, $value)
133 $_COOKIE[(string) $key] = $value;
138 * Set multiple cookies at once
140 * @param array $cookies
143 public function setCookies(array $cookies)
145 foreach ($cookies as $key => $value) {
146 $_COOKIE[$key] = $value;
154 * @return Zend_Controller_Request_HttpTestCase
156 public function clearCookies()
165 * @param string $type
166 * @return Zend_Controller_Request_HttpTestCase
168 public function setMethod($type)
170 $type = strtoupper(trim((string) $type));
171 if (!in_array($type, $this->_validMethodTypes
)) {
172 require_once 'Zend/Controller/Exception.php';
173 throw new Zend_Controller_Exception('Invalid request method specified');
175 $this->_method
= $type;
182 * @return string|null
184 public function getMethod()
186 return $this->_method
;
190 * Set a request header
193 * @param string $value
194 * @return Zend_Controller_Request_HttpTestCase
196 public function setHeader($key, $value)
198 $key = $this->_normalizeHeaderName($key);
199 $this->_headers
[$key] = (string) $value;
204 * Set request headers
206 * @param array $headers
207 * @return Zend_Controller_Request_HttpTestCase
209 public function setHeaders(array $headers)
211 foreach ($headers as $key => $value) {
212 $this->setHeader($key, $value);
220 * @param string $header
221 * @param mixed $default
222 * @return string|null
224 public function getHeader($header, $default = null)
226 $header = $this->_normalizeHeaderName($header);
227 if (array_key_exists($header, $this->_headers
)) {
228 return $this->_headers
[$header];
234 * Get all request headers
238 public function getHeaders()
240 return $this->_headers
;
244 * Clear request headers
246 * @return Zend_Controller_Request_HttpTestCase
248 public function clearHeaders()
250 $this->_headers
= array();
257 * @return null|string
259 public function getRequestUri()
261 return $this->_requestUri
;
265 * Normalize a header name for setting and retrieval
267 * @param string $name
270 protected function _normalizeHeaderName($name)
272 $name = strtoupper((string) $name);
273 $name = str_replace('-', '_', $name);