Completed
Push — master ( eba3de...910cad )
by Henry
08:56
created

RequestTest::testGlobal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
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('session', $actualArray);
99
		$this->assertArrayHasKey('cookie', $actualArray);
100
	}
101
102
	/**
103
	 * testGetAndSetServer
104
	 *
105
	 * @since 2.2.0
106
	 */
107
108
	public function testGetAndSetServer() : void
109
	{
110
		/* setup */
111
112
		$this->_request->setServer('testKey', 'testValue');
113
114
		/* actual */
115
116
		$actual = $this->_request->getServer('testKey');
117
118
		/* compare */
119
120
		$this->assertEquals('testValue', $actual);
121
	}
122
123
	/**
124
	 * testGetServerInvalid
125
	 *
126
	 * @since 4.0.0
127
	 */
128
129
	public function testGetServerInvalid() : void
130
	{
131
		/* actual */
132
133
		$actual = $this->_request->getServer('invalid');
134
135
		/* compare */
136
137
		$this->assertNull($actual);
138
	}
139
140
	/**
141
	 * testGetAndSetQuery
142
	 *
143
	 * @since 2.2.0
144
	 */
145
146
	public function testGetAndSetQuery() : void
147
	{
148
		/* setup */
149
150
		$this->_request->setQuery('testKey', 'testValue');
151
152
		/* actual */
153
154
		$actual = $this->_request->getQuery('testKey');
155
156
		/* compare */
157
158
		$this->assertEquals('testValue', $actual);
159
	}
160
161
	/**
162
	 * testGetQueryInvalid
163
	 *
164
	 * @since 4.0.0
165
	 */
166
167
	public function testGetQueryInvalid() : void
168
	{
169
		/* actual */
170
171
		$actual = $this->_request->getQuery('invalid');
172
173
		/* compare */
174
175
		$this->assertNull($actual);
176
	}
177
178
	/**
179
	 * testGetAndSetPost
180
	 *
181
	 * @since 2.2.0
182
	 */
183
184
	public function testGetAndSetPost() : void
185
	{
186
		/* setup */
187
188
		$this->_request->setPost('testKey', 'testValue');
189
190
		/* actual */
191
192
		$actual = $this->_request->getPost('testKey');
193
194
		/* compare */
195
196
		$this->assertEquals('testValue', $actual);
197
	}
198
199
	/**
200
	 * testGetPostInvalid
201
	 *
202
	 * @since 4.0.0
203
	 */
204
205
	public function testGetPostInvalid() : void
206
	{
207
		/* actual */
208
209
		$actual = $this->_request->getPost('invalid');
210
211
		/* compare */
212
213
		$this->assertNull($actual);
214
	}
215
216
	/**
217
	 * testGetAndSetFiles
218
	 *
219
	 * @since 3.9.0
220
	 */
221
222
	public function testGetAndSetFiles() : void
223
	{
224
		/* setup */
225
226
		$this->_request->setFiles('testKey', 'testValue');
227
228
		/* actual */
229
230
		$actual = $this->_request->getFiles('testKey');
231
232
		/* compare */
233
234
		$this->assertEquals('testValue', $actual);
235
	}
236
237
	/**
238
	 * testGetFilesInvalid
239
	 *
240
	 * @since 4.0.0
241
	 */
242
243
	public function testGetFilesInvalid() : void
244
	{
245
		/* actual */
246
247
		$actual = $this->_request->getFiles('invalid');
248
249
		/* compare */
250
251
		$this->assertNull($actual);
252
	}
253
254
	/**
255
	 * testGetAndSetAndRefreshSession
256
	 *
257
	 * @since 2.6.2
258
	 */
259
260
	public function testGetAndSetAndRefreshSession() : void
261
	{
262
		/* setup */
263
264
		$this->_request->setSession('testKey', 'testValue');
265
		$this->_request->refreshSession();
266
267
		/* actual */
268
269
		$actual = $this->_request->getSession('testKey');
270
271
		/* compare */
272
273
		$this->assertEquals('testValue', $actual);
274
	}
275
276
	/**
277
	 * testGetSessionInvalid
278
	 *
279
	 * @since 4.0.0
280
	 */
281
282
	public function testGetSessionInvalid() : void
283
	{
284
		/* actual */
285
286
		$actual = $this->_request->getSession('invalid');
287
288
		/* compare */
289
290
		$this->assertNull($actual);
291
	}
292
293
	/**
294
	 * testGetAndSetAndRefreshCookie
295
	 *
296
	 * @since 2.6.2
297
	 */
298
299
	public function testGetAndSetAndRefreshCookie() : void
300
	{
301
		/* setup */
302
303
		$this->_request->setCookie('testKey', 'testValue');
304
		$this->_request->refreshCookie();
305
306
		/* actual */
307
308
		$actual = $this->_request->getCookie('testKey');
309
310
		/* compare */
311
312
		$this->assertEquals('testValue', $actual);
313
	}
314
315
	/**
316
	 * testGetCookieInvalid
317
	 *
318
	 * @since 4.0.0
319
	 */
320
321
	public function testGetCookieInvalid() : void
322
	{
323
		/* actual */
324
325
		$actual = $this->_request->getCookie('invalid');
326
327
		/* compare */
328
329
		$this->assertNull($actual);
330
	}
331
}
332