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
|
|
|
* testGet |
41
|
|
|
* |
42
|
|
|
* @since 4.0.0 |
43
|
|
|
*/ |
44
|
|
|
|
45
|
|
|
public function testGet() : void |
46
|
|
|
{ |
47
|
|
|
/* actual */ |
48
|
|
|
|
49
|
|
|
$actualArray = $this->_request->get('server'); |
50
|
|
|
|
51
|
|
|
/* compare */ |
52
|
|
|
|
53
|
|
|
$this->assertArrayHasKey('argv', $actualArray); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* testGetArray |
58
|
|
|
* |
59
|
|
|
* @since 4.0.0 |
60
|
|
|
*/ |
61
|
|
|
|
62
|
|
|
public function testGetArray() : void |
63
|
|
|
{ |
64
|
|
|
/* actual */ |
65
|
|
|
|
66
|
|
|
$actualArray = $this->_request->getArray(); |
67
|
|
|
|
68
|
|
|
/* compare */ |
69
|
|
|
|
70
|
|
|
$this->assertArrayHasKey('server', $actualArray); |
71
|
|
|
$this->assertArrayHasKey('get', $actualArray); |
72
|
|
|
$this->assertArrayHasKey('post', $actualArray); |
73
|
|
|
$this->assertArrayHasKey('files', $actualArray); |
74
|
|
|
$this->assertArrayHasKey('session', $actualArray); |
75
|
|
|
$this->assertArrayHasKey('cookie', $actualArray); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* testGlobal |
80
|
|
|
* |
81
|
|
|
* @since 2.2.0 |
82
|
|
|
*/ |
83
|
|
|
|
84
|
|
|
public function testGlobal() : void |
85
|
|
|
{ |
86
|
|
|
/* setup */ |
87
|
|
|
|
88
|
|
|
$this->_request->set('testKey', 'testValue'); |
89
|
|
|
|
90
|
|
|
/* actual */ |
91
|
|
|
|
92
|
|
|
$actual = $this->_request->get('testKey'); |
93
|
|
|
|
94
|
|
|
/* compare */ |
95
|
|
|
|
96
|
|
|
$this->assertEquals('testValue', $actual); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* testServer |
101
|
|
|
* |
102
|
|
|
* @since 2.2.0 |
103
|
|
|
*/ |
104
|
|
|
|
105
|
|
|
public function testServer() : void |
106
|
|
|
{ |
107
|
|
|
/* setup */ |
108
|
|
|
|
109
|
|
|
$this->_request->setServer('testKey', 'testValue'); |
110
|
|
|
|
111
|
|
|
/* actual */ |
112
|
|
|
|
113
|
|
|
$actual = $this->_request->getServer('testKey'); |
114
|
|
|
|
115
|
|
|
/* compare */ |
116
|
|
|
|
117
|
|
|
$this->assertEquals('testValue', $actual); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* testQuery |
122
|
|
|
* |
123
|
|
|
* @since 2.2.0 |
124
|
|
|
*/ |
125
|
|
|
|
126
|
|
|
public function testQuery() : void |
127
|
|
|
{ |
128
|
|
|
/* setup */ |
129
|
|
|
|
130
|
|
|
$this->_request->setQuery('testKey', 'testValue'); |
131
|
|
|
|
132
|
|
|
/* actual */ |
133
|
|
|
|
134
|
|
|
$actual = $this->_request->getQuery('testKey'); |
135
|
|
|
|
136
|
|
|
/* compare */ |
137
|
|
|
|
138
|
|
|
$this->assertEquals('testValue', $actual); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* testPost |
143
|
|
|
* |
144
|
|
|
* @since 2.2.0 |
145
|
|
|
*/ |
146
|
|
|
|
147
|
|
|
public function testPost() : void |
148
|
|
|
{ |
149
|
|
|
/* setup */ |
150
|
|
|
|
151
|
|
|
$this->_request->setPost('testKey', 'testValue'); |
152
|
|
|
|
153
|
|
|
/* actual */ |
154
|
|
|
|
155
|
|
|
$actual = $this->_request->getPost('testKey'); |
156
|
|
|
|
157
|
|
|
/* compare */ |
158
|
|
|
|
159
|
|
|
$this->assertEquals('testValue', $actual); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* testFiles |
164
|
|
|
* |
165
|
|
|
* @since 3.9.0 |
166
|
|
|
*/ |
167
|
|
|
|
168
|
|
|
public function testFiles() : void |
169
|
|
|
{ |
170
|
|
|
/* setup */ |
171
|
|
|
|
172
|
|
|
$this->_request->setFiles('testKey', 'testValue'); |
173
|
|
|
|
174
|
|
|
/* actual */ |
175
|
|
|
|
176
|
|
|
$actual = $this->_request->getFiles('testKey'); |
177
|
|
|
|
178
|
|
|
/* compare */ |
179
|
|
|
|
180
|
|
|
$this->assertEquals('testValue', $actual); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* testSession |
185
|
|
|
* |
186
|
|
|
* @since 2.6.2 |
187
|
|
|
*/ |
188
|
|
|
|
189
|
|
|
public function testSession() : void |
190
|
|
|
{ |
191
|
|
|
/* setup */ |
192
|
|
|
|
193
|
|
|
$this->_request->setSession('testKey', 'testValue'); |
194
|
|
|
$this->_request->refreshSession(); |
195
|
|
|
|
196
|
|
|
/* actual */ |
197
|
|
|
|
198
|
|
|
$actual = $this->_request->getSession('testKey'); |
199
|
|
|
|
200
|
|
|
/* compare */ |
201
|
|
|
|
202
|
|
|
$this->assertEquals('testValue', $actual); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* testCookie |
207
|
|
|
* |
208
|
|
|
* @since 2.6.2 |
209
|
|
|
*/ |
210
|
|
|
|
211
|
|
|
public function testCookie() : void |
212
|
|
|
{ |
213
|
|
|
/* setup */ |
214
|
|
|
|
215
|
|
|
$this->_request->setCookie('testKey', 'testValue'); |
216
|
|
|
$this->_request->refreshCookie(); |
217
|
|
|
|
218
|
|
|
/* actual */ |
219
|
|
|
|
220
|
|
|
$actual = $this->_request->getCookie('testKey'); |
221
|
|
|
|
222
|
|
|
/* compare */ |
223
|
|
|
|
224
|
|
|
$this->assertEquals('testValue', $actual); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* testGetInvalid |
229
|
|
|
* |
230
|
|
|
* @since 3.0.0 |
231
|
|
|
*/ |
232
|
|
|
|
233
|
|
|
public function testGetInvalid() : void |
234
|
|
|
{ |
235
|
|
|
/* actual */ |
236
|
|
|
|
237
|
|
|
$actual = $this->_request->get('invalidKey'); |
238
|
|
|
|
239
|
|
|
/* compare */ |
240
|
|
|
|
241
|
|
|
$this->assertNull($actual); |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|