Completed
Push — master ( 029209...f1e0df )
by Henry
07:03
created

ParameterTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Redaxscript\Tests\Router;
3
4
use Redaxscript\Router;
5
use Redaxscript\Tests\TestCaseAbstract;
6
7
/**
8
 * ParameterTest
9
 *
10
 * @since 2.4.0
11
 *
12
 * @package Redaxscript
13
 * @category Tests
14
 * @author Henry Ruhs
15
 *
16
 * @covers Redaxscript\Router\Parameter
17
 */
18
19
class ParameterTest extends TestCaseAbstract
20
{
21
	/**
22
	 * setUp
23
	 *
24
	 * @since 5.0.0
25
	 */
26
27
	public function setUp() : void
28
	{
29
		parent::setUp();
30
		$this->_request->init();
31
	}
32
33
	/**
34
	 * testGetFirst
35
	 *
36
	 * @since 3.1.0
37
	 *
38
	 * @param string $route
39
	 * @param array $expectArray
40
	 *
41
	 * @dataProvider providerAutoloader
42
	 */
43
44
	public function testGetFirst(string $route = null, array $expectArray = []) : void
45
	{
46
		/* setup */
47
48
		$this->_request->setQuery('p', $route);
49
		$parameter = new Router\Parameter($this->_request);
50
		$parameter->init();
51
52
		/* actual */
53
54
		$actualArray =
55
		[
56
			'first' => $parameter->getFirst(),
57
			'firstSub' => $parameter->getFirstSub()
58
		];
59
60
		/* compare */
61
62
		$this->assertEquals($expectArray['first'], $actualArray['first']);
63
		$this->assertEquals($expectArray['firstSub'], $actualArray['firstSub']);
64
	}
65
66
	/**
67
	 * testGetSecond
68
	 *
69
	 * @since 3.1.0
70
	 *
71
	 * @param string $route
72
	 * @param array $expectArray
73
	 *
74
	 * @dataProvider providerAutoloader
75
	 */
76
77
	public function testGetSecond(string $route = null, array $expectArray = []) : void
78
	{
79
		/* setup */
80
81
		$this->_request->setQuery('p', $route);
82
		$parameter = new Router\Parameter($this->_request);
83
		$parameter->init();
84
85
		/* actual */
86
87
		$actualArray =
88
		[
89
			'second' => $parameter->getSecond(),
90
			'secondSub' => $parameter->getSecondSub()
91
		];
92
93
		/* compare */
94
95
		$this->assertEquals($expectArray['second'], $actualArray['second']);
96
		$this->assertEquals($expectArray['secondSub'], $actualArray['secondSub']);
97
	}
98
99
	/**
100
	 * testGetThird
101
	 *
102
	 * @since 2.4.0
103
	 *
104
	 * @param string $route
105
	 * @param array $expectArray
106
	 *
107
	 * @dataProvider providerAutoloader
108
	 */
109
110
	public function testGetThird(string $route = null, array $expectArray = []) : void
111
	{
112
		/* setup */
113
114
		$this->_request->setQuery('p', $route);
115
		$parameter = new Router\Parameter($this->_request);
116
		$parameter->init();
117
118
		/* actual */
119
120
		$actualArray =
121
		[
122
			'third' => $parameter->getThird(),
123
			'thirdSub' => $parameter->getThirdSub(),
124
		];
125
126
		/* compare */
127
128
		$this->assertEquals($expectArray['third'], $actualArray['third']);
129
		$this->assertEquals($expectArray['thirdSub'], $actualArray['thirdSub']);
130
	}
131
132
	/**
133
	 * testGetFourth
134
	 *
135
	 * @since 2.4.0
136
	 *
137
	 * @param string $route
138
	 * @param array $expectArray
139
	 *
140
	 * @dataProvider providerAutoloader
141
	 */
142
143
	public function testGetFourth(string $route = null, array $expectArray = []) : void
144
	{
145
		/* setup */
146
147
		$this->_request->setQuery('p', $route);
148
		$parameter = new Router\Parameter($this->_request);
149
		$parameter->init();
150
151
		/* actual */
152
153
		$actualArray =
154
		[
155
			'fourth' => $parameter->getFourth(),
156
			'fourthSub' => $parameter->getFourthSub(),
157
		];
158
159
		/* compare */
160
161
		$this->assertEquals($expectArray['fourth'], $actualArray['fourth']);
162
		$this->assertEquals($expectArray['fourthSub'], $actualArray['fourthSub']);
163
	}
164
165
	/**
166
	 * testGetLast
167
	 *
168
	 * @since 2.4.0
169
	 *
170
	 * @param string $route
171
	 * @param array $expectArray
172
	 *
173
	 * @dataProvider providerAutoloader
174
	 */
175
176
	public function testGetLast(string $route = null, array $expectArray = []) : void
177
	{
178
		/* setup */
179
180
		$this->_request->setQuery('p', $route);
181
		$parameter = new Router\Parameter($this->_request);
182
		$parameter->init();
183
184
		/* actual */
185
186
		$actualArray =
187
		[
188
			'last' => $parameter->getLast(),
189
			'lastSub' => $parameter->getLastSub()
190
		];
191
192
		/* compare */
193
194
		$this->assertEquals($expectArray['last'], $actualArray['last']);
195
		$this->assertEquals($expectArray['lastSub'], $actualArray['lastSub']);
196
	}
197
198
	/**
199
	 * testGetAdmin
200
	 *
201
	 * @since 2.4.0
202
	 *
203
	 * @param string $route
204
	 * @param array $expectArray
205
	 *
206
	 * @dataProvider providerAutoloader
207
	 */
208
209
	public function testGetAdmin(string $route = null, array $expectArray = []) : void
210
	{
211
		/* setup */
212
213
		$this->_request->setQuery('p', $route);
214
		$parameter = new Router\Parameter($this->_request);
215
		$parameter->init();
216
217
		/* actual */
218
219
		$actual = $parameter->getAdmin();
220
221
		/* compare */
222
223
		$this->assertEquals($expectArray['admin'], $actual);
224
	}
225
226
	/**
227
	 * testGetTable
228
	 *
229
	 * @since 2.4.0
230
	 *
231
	 * @param string $route
232
	 * @param array $expectArray
233
	 *
234
	 * @dataProvider providerAutoloader
235
	 */
236
237
	public function testGetTable(string $route = null, array $expectArray = []) : void
238
	{
239
		/* setup */
240
241
		$this->_request->setQuery('p', $route);
242
		$parameter = new Router\Parameter($this->_request);
243
		$parameter->init();
244
245
		/* actual */
246
247
		$actual = $parameter->getTable();
248
249
		/* compare */
250
251
		$this->assertEquals($expectArray['table'], $actual);
252
	}
253
254
	/**
255
	 * testGetAlias
256
	 *
257
	 * @since 2.4.0
258
	 *
259
	 * @param string $route
260
	 * @param array $expectArray
261
	 *
262
	 * @dataProvider providerAutoloader
263
	 */
264
265
	public function testGetAlias(string $route = null, array $expectArray = []) : void
266
	{
267
		/* setup */
268
269
		$this->_request->setQuery('p', $route);
270
		$parameter = new Router\Parameter($this->_request);
271
		$parameter->init();
272
273
		/* actual */
274
275
		$actual = $parameter->getAlias();
276
277
		/* compare */
278
279
		$this->assertEquals($expectArray['alias'], $actual);
280
	}
281
282
	/**
283
	 * testGetId
284
	 *
285
	 * @since 2.4.0
286
	 *
287
	 * @param string $route
288
	 * @param array $expectArray
289
	 *
290
	 * @dataProvider providerAutoloader
291
	 */
292
293
	public function testGetId(string $route = null, array $expectArray = []) : void
294
	{
295
		/* setup */
296
297
		$this->_request->setQuery('p', $route);
298
		$parameter = new Router\Parameter($this->_request);
299
		$parameter->init();
300
301
		/* actual */
302
303
		$actual = $parameter->getId();
304
305
		/* compare */
306
307
		$this->assertEquals($expectArray['id'], $actual);
308
	}
309
310
	/**
311
	 * testGetToken
312
	 *
313
	 * @since 2.4.0
314
	 *
315
	 * @param string $route
316
	 * @param array $expectArray
317
	 *
318
	 * @dataProvider providerAutoloader
319
	 */
320
321
	public function testGetToken(string $route = null, array $expectArray = []) : void
322
	{
323
		/* setup */
324
325
		$this->_request->setQuery('p', $route);
326
		$this->_request->set('server',
327
		[
328
			'HTTP_HOST' => 'localhost',
329
			'HTTP_USER_AGENT' => 'redaxscript',
330
			'REMOTE_ADDR' => 'localhost'
331
		]);
332
		$parameter = new Router\Parameter($this->_request);
333
		$parameter->init();
334
335
		/* actual */
336
337
		$actual = $parameter->getToken();
338
339
		/* compare */
340
341
		$this->assertEquals($expectArray['token'], $actual);
342
	}
343
}
344