~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Controller/Request/HttpTestCase.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
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.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Controller
 
17
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
18
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
19
 */
 
20
 
 
21
/**
 
22
 * @see Zend_Controller_Request_Http
 
23
 */
 
24
require_once 'Zend/Controller/Request/Http.php';
 
25
 
 
26
/**
 
27
 * Zend_Controller_Request_HttpTestCase
 
28
 *
 
29
 * HTTP request object for use with Zend_Controller family.
 
30
 *
 
31
 * @uses Zend_Controller_Request_Http
 
32
 * @package Zend_Controller
 
33
 * @subpackage Request
 
34
 */
 
35
class Zend_Controller_Request_HttpTestCase extends Zend_Controller_Request_Http
 
36
{
 
37
    /**
 
38
     * Request headers
 
39
     * @var array
 
40
     */
 
41
    protected $_headers = array();
 
42
 
 
43
    /**
 
44
     * Request method
 
45
     * @var string
 
46
     */
 
47
    protected $_method;
 
48
 
 
49
    /**
 
50
     * Raw POST body
 
51
     * @var string|null
 
52
     */
 
53
    protected $_rawBody;
 
54
 
 
55
    /**
 
56
     * Valid request method types
 
57
     * @var array
 
58
     */
 
59
    protected $_validMethodTypes = array(
 
60
        'DELETE',
 
61
        'GET',
 
62
        'HEAD',
 
63
        'OPTIONS',
 
64
        'POST',
 
65
        'PUT',
 
66
    );
 
67
 
 
68
    /**
 
69
     * Clear GET values
 
70
     * 
 
71
     * @return Zend_Controller_Request_HttpTestCase
 
72
     */
 
73
    public function clearQuery()
 
74
    {
 
75
        $_GET = array();
 
76
        return $this;
 
77
    }
 
78
 
 
79
    /**
 
80
     * Clear POST values
 
81
     * 
 
82
     * @return Zend_Controller_Request_HttpTestCase
 
83
     */
 
84
    public function clearPost()
 
85
    {
 
86
        $_POST = array();
 
87
        return $this;
 
88
    }
 
89
 
 
90
    /**
 
91
     * Set raw POST body
 
92
     * 
 
93
     * @param  string $content 
 
94
     * @return Zend_Controller_Request_HttpTestCase
 
95
     */
 
96
    public function setRawBody($content)
 
97
    {
 
98
        $this->_rawBody = (string) $content;
 
99
        return $this;
 
100
    }
 
101
 
 
102
    /**
 
103
     * Get RAW POST body
 
104
     * 
 
105
     * @return string|null
 
106
     */
 
107
    public function getRawBody()
 
108
    {
 
109
        return $this->_rawBody;
 
110
    }
 
111
 
 
112
    /**
 
113
     * Clear raw POST body
 
114
     * 
 
115
     * @return Zend_Controller_Request_HttpTestCase
 
116
     */
 
117
    public function clearRawBody()
 
118
    {
 
119
        $this->_rawBody = null;
 
120
        return $this;
 
121
    }
 
122
 
 
123
    /**
 
124
     * Set a cookie
 
125
     * 
 
126
     * @param  string $key 
 
127
     * @param  mixed $value 
 
128
     * @return Zend_Controller_Request_HttpTestCase
 
129
     */
 
130
    public function setCookie($key, $value)
 
131
    {
 
132
        $_COOKIE[(string) $key] = $value;
 
133
        return $this;
 
134
    }
 
135
 
 
136
    /**
 
137
     * Set multiple cookies at once
 
138
     * 
 
139
     * @param array $cookies 
 
140
     * @return void
 
141
     */
 
142
    public function setCookies(array $cookies)
 
143
    {
 
144
        foreach ($cookies as $key => $value) {
 
145
            $_COOKIE[$key] = $value;
 
146
        }
 
147
        return $this;
 
148
    }
 
149
 
 
150
    /**
 
151
     * Clear all cookies
 
152
     * 
 
153
     * @return Zend_Controller_Request_HttpTestCase
 
154
     */
 
155
    public function clearCookies()
 
156
    {
 
157
        $_COOKIE = array();
 
158
        return $this;
 
159
    }
 
160
 
 
161
    /**
 
162
     * Set request method
 
163
     * 
 
164
     * @param  string $type 
 
165
     * @return Zend_Controller_Request_HttpTestCase
 
166
     */
 
167
    public function setMethod($type)
 
168
    {
 
169
        $type = strtoupper(trim((string) $type));
 
170
        if (!in_array($type, $this->_validMethodTypes)) {
 
171
            require_once 'Zend/Controller/Exception.php';
 
172
            throw new Zend_Controller_Exception('Invalid request method specified');
 
173
        }
 
174
        $this->_method = $type;
 
175
        return $this;
 
176
    }
 
177
 
 
178
    /**
 
179
     * Get request method
 
180
     * 
 
181
     * @return string|null
 
182
     */
 
183
    public function getMethod()
 
184
    {
 
185
        return $this->_method;
 
186
    }
 
187
 
 
188
    /**
 
189
     * Set a request header
 
190
     * 
 
191
     * @param  string $key 
 
192
     * @param  string $value 
 
193
     * @return Zend_Controller_Request_HttpTestCase
 
194
     */
 
195
    public function setHeader($key, $value)
 
196
    {
 
197
        $key = $this->_normalizeHeaderName($key);
 
198
        $this->_headers[$key] = (string) $value;
 
199
        return $this;
 
200
    }
 
201
 
 
202
    /**
 
203
     * Set request headers
 
204
     * 
 
205
     * @param  array $headers 
 
206
     * @return Zend_Controller_Request_HttpTestCase
 
207
     */
 
208
    public function setHeaders(array $headers)
 
209
    {
 
210
        foreach ($headers as $key => $value) {
 
211
            $this->setHeader($key, $value);
 
212
        }
 
213
        return $this;
 
214
    }
 
215
 
 
216
    /**
 
217
     * Get request header
 
218
     * 
 
219
     * @param  string $header 
 
220
     * @param  mixed $default 
 
221
     * @return string|null
 
222
     */
 
223
    public function getHeader($header, $default = null)
 
224
    {
 
225
        $header = $this->_normalizeHeaderName($header);
 
226
        if (array_key_exists($header, $this->_headers)) {
 
227
            return $this->_headers[$header];
 
228
        }
 
229
        return $default;
 
230
    }
 
231
 
 
232
    /**
 
233
     * Get all request headers
 
234
     * 
 
235
     * @return array
 
236
     */
 
237
    public function getHeaders()
 
238
    {
 
239
        return $this->_headers;
 
240
    }
 
241
 
 
242
    /**
 
243
     * Clear request headers
 
244
     * 
 
245
     * @return Zend_Controller_Request_HttpTestCase
 
246
     */
 
247
    public function clearHeaders()
 
248
    {
 
249
        $this->_headers = array();
 
250
        return $this;
 
251
    }
 
252
 
 
253
    /**
 
254
     * Get REQUEST_URI
 
255
     * 
 
256
     * @return null|string
 
257
     */
 
258
    public function getRequestUri()
 
259
    {
 
260
        return $this->_requestUri;
 
261
    }
 
262
 
 
263
    /**
 
264
     * Normalize a header name for setting and retrieval
 
265
     * 
 
266
     * @param  string $name 
 
267
     * @return string
 
268
     */
 
269
    protected function _normalizeHeaderName($name)
 
270
    {
 
271
        $name = strtoupper((string) $name);
 
272
        $name = str_replace('-', '_', $name);
 
273
        return $name;
 
274
    }
 
275
}