1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Tests; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* RequestTest |
6
|
|
|
* |
7
|
|
|
* @since 2.2.0 |
8
|
|
|
* |
9
|
|
|
* @package Redaxscript |
10
|
|
|
* @category Tests |
11
|
|
|
* @author Henry Ruhs |
12
|
|
|
* |
13
|
|
|
* @covers Redaxscript\Request |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
class RequestTest extends TestCaseAbstract |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* testInit |
20
|
|
|
* |
21
|
|
|
* @since 3.0.0 |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
public function testInit() : void |
25
|
|
|
{ |
26
|
|
|
/* setup */ |
27
|
|
|
|
28
|
|
|
$this->_request->init(); |
29
|
|
|
|
30
|
|
|
/* actual */ |
31
|
|
|
|
32
|
|
|
$actual = $this->_request; |
33
|
|
|
|
34
|
|
|
/* compare */ |
35
|
|
|
|
36
|
|
|
$this->assertInstanceOf('Redaxscript\Request', $actual); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* testGetAndSet |
41
|
|
|
* |
42
|
|
|
* @since 4.0.0 |
43
|
|
|
*/ |
44
|
|
|
|
45
|
|
|
public function testGetAndSet() : void |
46
|
|
|
{ |
47
|
|
|
/* setup */ |
48
|
|
|
|
49
|
|
|
$this->_request->set('testKey', |
50
|
|
|
[ |
51
|
|
|
'testValue' |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
/* actual */ |
55
|
|
|
|
56
|
|
|
$actualArray = $this->_request->get('testKey'); |
57
|
|
|
|
58
|
|
|
/* compare */ |
59
|
|
|
|
60
|
|
|
$this->assertContains('testValue', $actualArray); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* testGetInvalid |
65
|
|
|
* |
66
|
|
|
* @since 4.0.0 |
67
|
|
|
*/ |
68
|
|
|
|
69
|
|
|
public function testGetInvalid() : void |
70
|
|
|
{ |
71
|
|
|
/* actual */ |
72
|
|
|
|
73
|
|
|
$actual = $this->_request->get('invalid'); |
74
|
|
|
|
75
|
|
|
/* compare */ |
76
|
|
|
|
77
|
|
|
$this->assertNull($actual); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* testGetArray |
82
|
|
|
* |
83
|
|
|
* @since 4.0.0 |
84
|
|
|
*/ |
85
|
|
|
|
86
|
|
|
public function testGetArray() : void |
87
|
|
|
{ |
88
|
|
|
/* actual */ |
89
|
|
|
|
90
|
|
|
$actualArray = $this->_request->getArray(); |
91
|
|
|
|
92
|
|
|
/* compare */ |
93
|
|
|
|
94
|
|
|
$this->assertArrayHasKey('server', $actualArray); |
95
|
|
|
$this->assertArrayHasKey('get', $actualArray); |
96
|
|
|
$this->assertArrayHasKey('post', $actualArray); |
97
|
|
|
$this->assertArrayHasKey('files', $actualArray); |
98
|
|
|
$this->assertArrayHasKey('stream', $actualArray); |
99
|
|
|
$this->assertArrayHasKey('session', $actualArray); |
100
|
|
|
$this->assertArrayHasKey('cookie', $actualArray); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* testGetAndSetServer |
105
|
|
|
* |
106
|
|
|
* @since 2.2.0 |
107
|
|
|
*/ |
108
|
|
|
|
109
|
|
|
public function testGetAndSetServer() : void |
110
|
|
|
{ |
111
|
|
|
/* setup */ |
112
|
|
|
|
113
|
|
|
$this->_request->setServer('testKey', 'testValue'); |
114
|
|
|
|
115
|
|
|
/* actual */ |
116
|
|
|
|
117
|
|
|
$actual = $this->_request->getServer('testKey'); |
118
|
|
|
|
119
|
|
|
/* compare */ |
120
|
|
|
|
121
|
|
|
$this->assertEquals('testValue', $actual); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* testGetServerInvalid |
126
|
|
|
* |
127
|
|
|
* @since 4.0.0 |
128
|
|
|
*/ |
129
|
|
|
|
130
|
|
|
public function testGetServerInvalid() : void |
131
|
|
|
{ |
132
|
|
|
/* actual */ |
133
|
|
|
|
134
|
|
|
$actual = $this->_request->getServer('invalid'); |
135
|
|
|
|
136
|
|
|
/* compare */ |
137
|
|
|
|
138
|
|
|
$this->assertNull($actual); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* testGetAndSetQuery |
143
|
|
|
* |
144
|
|
|
* @since 2.2.0 |
145
|
|
|
*/ |
146
|
|
|
|
147
|
|
|
public function testGetAndSetQuery() : void |
148
|
|
|
{ |
149
|
|
|
/* setup */ |
150
|
|
|
|
151
|
|
|
$this->_request->setQuery('testKey', 'testValue'); |
152
|
|
|
|
153
|
|
|
/* actual */ |
154
|
|
|
|
155
|
|
|
$actual = $this->_request->getQuery('testKey'); |
156
|
|
|
|
157
|
|
|
/* compare */ |
158
|
|
|
|
159
|
|
|
$this->assertEquals('testValue', $actual); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* testGetQueryInvalid |
164
|
|
|
* |
165
|
|
|
* @since 4.0.0 |
166
|
|
|
*/ |
167
|
|
|
|
168
|
|
|
public function testGetQueryInvalid() : void |
169
|
|
|
{ |
170
|
|
|
/* actual */ |
171
|
|
|
|
172
|
|
|
$actual = $this->_request->getQuery('invalid'); |
173
|
|
|
|
174
|
|
|
/* compare */ |
175
|
|
|
|
176
|
|
|
$this->assertNull($actual); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* testGetAndSetPost |
181
|
|
|
* |
182
|
|
|
* @since 2.2.0 |
183
|
|
|
*/ |
184
|
|
|
|
185
|
|
|
public function testGetAndSetPost() : void |
186
|
|
|
{ |
187
|
|
|
/* setup */ |
188
|
|
|
|
189
|
|
|
$this->_request->setPost('testKey', 'testValue'); |
190
|
|
|
|
191
|
|
|
/* actual */ |
192
|
|
|
|
193
|
|
|
$actual = $this->_request->getPost('testKey'); |
194
|
|
|
|
195
|
|
|
/* compare */ |
196
|
|
|
|
197
|
|
|
$this->assertEquals('testValue', $actual); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* testGetPostInvalid |
202
|
|
|
* |
203
|
|
|
* @since 4.0.0 |
204
|
|
|
*/ |
205
|
|
|
|
206
|
|
|
public function testGetPostInvalid() : void |
207
|
|
|
{ |
208
|
|
|
/* actual */ |
209
|
|
|
|
210
|
|
|
$actual = $this->_request->getPost('invalid'); |
211
|
|
|
|
212
|
|
|
/* compare */ |
213
|
|
|
|
214
|
|
|
$this->assertNull($actual); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* testGetAndSetFiles |
219
|
|
|
* |
220
|
|
|
* @since 3.9.0 |
221
|
|
|
*/ |
222
|
|
|
|
223
|
|
|
public function testGetAndSetFiles() : void |
224
|
|
|
{ |
225
|
|
|
/* setup */ |
226
|
|
|
|
227
|
|
|
$this->_request->setFiles('testKey', 'testValue'); |
228
|
|
|
|
229
|
|
|
/* actual */ |
230
|
|
|
|
231
|
|
|
$actual = $this->_request->getFiles('testKey'); |
232
|
|
|
|
233
|
|
|
/* compare */ |
234
|
|
|
|
235
|
|
|
$this->assertEquals('testValue', $actual); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* testGetFilesInvalid |
240
|
|
|
* |
241
|
|
|
* @since 4.0.0 |
242
|
|
|
*/ |
243
|
|
|
|
244
|
|
|
public function testGetFilesInvalid() : void |
245
|
|
|
{ |
246
|
|
|
/* actual */ |
247
|
|
|
|
248
|
|
|
$actual = $this->_request->getFiles('invalid'); |
249
|
|
|
|
250
|
|
|
/* compare */ |
251
|
|
|
|
252
|
|
|
$this->assertNull($actual); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* testGetAndSetServer |
257
|
|
|
* |
258
|
|
|
* @since 4.2.0 |
259
|
|
|
*/ |
260
|
|
|
|
261
|
|
|
public function testGetAndSetStream() : void |
262
|
|
|
{ |
263
|
|
|
/* setup */ |
264
|
|
|
|
265
|
|
|
$this->_request->setStream('testKey', 'testValue'); |
266
|
|
|
|
267
|
|
|
/* actual */ |
268
|
|
|
|
269
|
|
|
$actual = $this->_request->getStream('testKey'); |
270
|
|
|
|
271
|
|
|
/* compare */ |
272
|
|
|
|
273
|
|
|
$this->assertEquals('testValue', $actual); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* testGetStreamInvalid |
278
|
|
|
* |
279
|
|
|
* @since 4.2.0 |
280
|
|
|
*/ |
281
|
|
|
|
282
|
|
|
public function testGetStreamInvalid() : void |
283
|
|
|
{ |
284
|
|
|
/* actual */ |
285
|
|
|
|
286
|
|
|
$actual = $this->_request->getStream('invalid'); |
287
|
|
|
|
288
|
|
|
/* compare */ |
289
|
|
|
|
290
|
|
|
$this->assertNull($actual); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* testGetAndSetAndRefreshSession |
295
|
|
|
* |
296
|
|
|
* @since 2.6.2 |
297
|
|
|
*/ |
298
|
|
|
|
299
|
|
|
public function testGetAndSetAndRefreshSession() : void |
300
|
|
|
{ |
301
|
|
|
/* setup */ |
302
|
|
|
|
303
|
|
|
$this->_request->setSession('testKey', 'testValue'); |
304
|
|
|
$this->_request->refreshSession(); |
305
|
|
|
|
306
|
|
|
/* actual */ |
307
|
|
|
|
308
|
|
|
$actual = $this->_request->getSession('testKey'); |
309
|
|
|
|
310
|
|
|
/* compare */ |
311
|
|
|
|
312
|
|
|
$this->assertEquals('testValue', $actual); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* testGetSessionInvalid |
317
|
|
|
* |
318
|
|
|
* @since 4.0.0 |
319
|
|
|
*/ |
320
|
|
|
|
321
|
|
|
public function testGetSessionInvalid() : void |
322
|
|
|
{ |
323
|
|
|
/* actual */ |
324
|
|
|
|
325
|
|
|
$actual = $this->_request->getSession('invalid'); |
326
|
|
|
|
327
|
|
|
/* compare */ |
328
|
|
|
|
329
|
|
|
$this->assertNull($actual); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* testGetAndSetAndRefreshCookie |
334
|
|
|
* |
335
|
|
|
* @since 2.6.2 |
336
|
|
|
*/ |
337
|
|
|
|
338
|
|
|
public function testGetAndSetAndRefreshCookie() : void |
339
|
|
|
{ |
340
|
|
|
/* setup */ |
341
|
|
|
|
342
|
|
|
$this->_request->setCookie('testKey', 'testValue'); |
343
|
|
|
$this->_request->refreshCookie(); |
344
|
|
|
|
345
|
|
|
/* actual */ |
346
|
|
|
|
347
|
|
|
$actual = $this->_request->getCookie('testKey'); |
348
|
|
|
|
349
|
|
|
/* compare */ |
350
|
|
|
|
351
|
|
|
$this->assertEquals('testValue', $actual); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* testGetCookieInvalid |
356
|
|
|
* |
357
|
|
|
* @since 4.0.0 |
358
|
|
|
*/ |
359
|
|
|
|
360
|
|
|
public function testGetCookieInvalid() : void |
361
|
|
|
{ |
362
|
|
|
/* actual */ |
363
|
|
|
|
364
|
|
|
$actual = $this->_request->getCookie('invalid'); |
365
|
|
|
|
366
|
|
|
/* compare */ |
367
|
|
|
|
368
|
|
|
$this->assertNull($actual); |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|