OptionTest   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 362
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 15
lcom 0
cbo 1
dl 0
loc 362
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 49 1
A tearDown() 0 4 1
A testGetRobotArray() 0 14 1
A testGetCharsetArray() 0 14 1
A testGetLocaleArray() 0 14 2
A testGetZoneArray() 0 14 1
A testGetTimeArray() 0 14 1
A testGetDateArray() 0 14 1
A testGetOrderArray() 0 14 1
A testGetCaptchaArray() 0 14 1
A testGetPermissionArray() 0 19 1
A testGetLanguageArray() 0 14 1
A testGetTemplateArray() 0 14 1
A testGetGroupArray() 0 14 1
1
<?php
2
namespace Redaxscript\Tests\Admin\View\Helper;
3
4
use Redaxscript\Admin;
5
use Redaxscript\Db;
6
use Redaxscript\Tests\TestCaseAbstract;
7
use function array_diff;
8
use function function_exists;
9
10
/**
11
 * OptionTest
12
 *
13
 * @since 3.0.0
14
 *
15
 * @package Redaxscript
16
 * @category Tests
17
 * @author Henry Ruhs
18
 *
19
 * @covers Redaxscript\Admin\View\Helper\Option
20
 */
21
22
class OptionTest extends TestCaseAbstract
23
{
24
	/**
25
	 * setUp
26
	 *
27
	 * @since 3.1.0
28
	 */
29
30
	public function setUp() : void
31
	{
32
		parent::setUp();
33
		$optionArray = $this->getOptionArray();
34
		$installer = $this->installerFactory();
35
		$installer->init();
36
		$installer->rawCreate();
37
		$installer->insertSettings($optionArray);
38
		Db::forTablePrefix('articles')
39
			->create()
40
			->set(
41
			[
42
				'title' => 'Article One',
43
				'alias' => 'article-one'
44
			])
45
			->save();
46
		Db::forTablePrefix('articles')
47
			->create()
48
			->set(
49
			[
50
				'title' => 'Article Two',
51
				'alias' => 'article-two'
52
			])
53
			->save();
54
		Db::forTablePrefix('articles')
55
			->create()
56
			->set(
57
			[
58
				'title' => 'Article Three',
59
				'alias' => 'article-three'
60
			])
61
			->save();
62
		Db::forTablePrefix('groups')
63
			->create()
64
			->set(
65
			[
66
				'name' => 'Group One',
67
				'alias' => 'group-one'
68
			])
69
			->save();
70
		Db::forTablePrefix('groups')
71
			->create()
72
			->set(
73
			[
74
				'name' => 'Group Two',
75
				'alias' => 'group-two'
76
			])
77
			->save();
78
	}
79
80
	/**
81
	 * tearDown
82
	 *
83
	 * @since 3.1.0
84
	 */
85
86
	public function tearDown() : void
87
	{
88
		$this->dropDatabase();
89
	}
90
91
	/**
92
	 * testGetRobotArray
93
	 *
94
	 * @since 3.0.0
95
	 *
96
	 * @param array $expectArray
97
	 *
98
	 * @dataProvider providerAutoloader
99
	 */
100
101
	public function testGetRobotArray(array $expectArray = []) : void
102
	{
103
		/* setup */
104
105
		$helperOption = new Admin\View\Helper\Option($this->_language);
106
107
		/* actual */
108
109
		$actualArray = $helperOption->getRobotArray();
110
111
		/* compare */
112
113
		$this->assertEquals($expectArray['robot'], $actualArray);
114
	}
115
116
	/**
117
	 * testGetCharsetArray
118
	 *
119
	 * @since 4.4.0
120
	 */
121
122
	public function testGetCharsetArray() : void
123
	{
124
		/* setup */
125
126
		$helperOption = new Admin\View\Helper\Option($this->_language);
127
128
		/* actual */
129
130
		$actualArray = $helperOption->getCharsetArray();
131
132
		/* compare */
133
134
		$this->assertContains('UTF-8', $actualArray);
135
	}
136
137
	/**
138
	 * testGetLocaleArray
139
	 *
140
	 * @since 4.4.0
141
	 */
142
143
	public function testGetLocaleArray() : void
144
	{
145
		/* setup */
146
147
		$helperOption = new Admin\View\Helper\Option($this->_language);
148
149
		/* actual */
150
151
		$actualArray = $helperOption->getLocaleArray();
152
153
		/* compare */
154
155
		function_exists('resourcebundle_locales') ? $this->assertContains('en_US', $actualArray) : $this->assertEmpty($actualArray);
156
	}
157
158
	/**
159
	 * testGetZoneArray
160
	 *
161
	 * @since 4.0.0
162
	 */
163
164
	public function testGetZoneArray() : void
165
	{
166
		/* setup */
167
168
		$helperOption = new Admin\View\Helper\Option($this->_language);
169
170
		/* actual */
171
172
		$actualArray = $helperOption->getZoneArray();
173
174
		/* compare */
175
176
		$this->assertContains('UTC', $actualArray);
177
	}
178
179
	/**
180
	 * testGetTimeArray
181
	 *
182
	 * @since 3.0.0
183
	 *
184
	 * @param array $expectArray
185
	 *
186
	 * @dataProvider providerAutoloader
187
	 */
188
189
	public function testGetTimeArray(array $expectArray = []) : void
190
	{
191
		/* setup */
192
193
		$helperOption = new Admin\View\Helper\Option($this->_language);
194
195
		/* actual */
196
197
		$actualArray = $helperOption->getTimeArray();
198
199
		/* compare */
200
201
		$this->assertEquals($expectArray['time'], $actualArray);
202
	}
203
204
	/**
205
	 * testGetDateArray
206
	 *
207
	 * @since 3.0.0
208
	 *
209
	 * @param array $expectArray
210
	 *
211
	 * @dataProvider providerAutoloader
212
	 */
213
214
	public function testGetDateArray(array $expectArray = []) : void
215
	{
216
		/* setup */
217
218
		$helperOption = new Admin\View\Helper\Option($this->_language);
219
220
		/* actual */
221
222
		$actualArray = $helperOption->getDateArray();
223
224
		/* compare */
225
226
		$this->assertEquals($expectArray['date'], $actualArray);
227
	}
228
229
	/**
230
	 * testGetOrderArray
231
	 *
232
	 * @since 3.0.0
233
	 *
234
	 * @param array $expectArray
235
	 *
236
	 * @dataProvider providerAutoloader
237
	 */
238
239
	public function testGetOrderArray(array $expectArray = []) : void
240
	{
241
		/* setup */
242
243
		$helperOption = new Admin\View\Helper\Option($this->_language);
244
245
		/* actual */
246
247
		$actualArray = $helperOption->getOrderArray();
248
249
		/* compare */
250
251
		$this->assertEquals($expectArray['order'], $actualArray);
252
	}
253
254
	/**
255
	 * testGetCaptchaArray
256
	 *
257
	 * @since 3.0.0
258
	 *
259
	 * @param array $expectArray
260
	 *
261
	 * @dataProvider providerAutoloader
262
	 */
263
264
	public function testGetCaptchaArray(array $expectArray = []) : void
265
	{
266
		/* setup */
267
268
		$helperOption = new Admin\View\Helper\Option($this->_language);
269
270
		/* actual */
271
272
		$actualArray = $helperOption->getCaptchaArray();
273
274
		/* compare */
275
276
		$this->assertEquals($expectArray['captcha'], $actualArray);
277
	}
278
279
	/**
280
	 * testGetPermissionArray
281
	 *
282
	 * @since 3.0.0
283
	 *
284
	 * @param array $expectArray
285
	 *
286
	 * @dataProvider providerAutoloader
287
	 */
288
289
	public function testGetPermissionArray(array $expectArray = []) : void
290
	{
291
		/* setup */
292
293
		$helperOption = new Admin\View\Helper\Option($this->_language);
294
295
		/* actual */
296
297
		$actualArray =
298
		[
299
			'articles' => $helperOption->getPermissionArray('articles'),
300
			'modules' => $helperOption->getPermissionArray('modules'),
301
			'settings' => $helperOption->getPermissionArray('settings')
302
		];
303
304
		/* compare */
305
306
		$this->assertEquals($expectArray['permission'], $actualArray);
307
	}
308
309
	/**
310
	 * testGetLanguageArray
311
	 *
312
	 * @since 3.0.0
313
	 *
314
	 * @param array $expectArray
315
	 *
316
	 * @dataProvider providerAutoloader
317
	 */
318
319
	public function testGetLanguageArray(array $expectArray = []) : void
320
	{
321
		/* setup */
322
323
		$helperOption = new Admin\View\Helper\Option($this->_language);
324
325
		/* actual */
326
327
		$actualArray = $helperOption->getLanguageArray();
328
329
		/* compare */
330
331
		$this->assertNotTrue(array_diff($expectArray['language'], $actualArray));
332
	}
333
334
	/**
335
	 * testGetTemplateArray
336
	 *
337
	 * @since 3.0.0
338
	 *
339
	 * @param array $expectArray
340
	 *
341
	 * @dataProvider providerAutoloader
342
	 */
343
344
	public function testGetTemplateArray(array $expectArray = []) : void
345
	{
346
		/* setup */
347
348
		$helperOption = new Admin\View\Helper\Option($this->_language);
349
350
		/* actual */
351
352
		$actualArray = $helperOption->getTemplateArray();
353
354
		/* compare */
355
356
		$this->assertNotTrue(array_diff($expectArray['template'], $actualArray));
357
	}
358
359
	/**
360
	 * testGetGroupArray
361
	 *
362
	 * @since 3.0.0
363
	 *
364
	 * @param array $expectArray
365
	 *
366
	 * @dataProvider providerAutoloader
367
	 */
368
369
	public function testGetGroupArray(array $expectArray = []) : void
370
	{
371
		/* setup */
372
373
		$helperOption = new Admin\View\Helper\Option($this->_language);
374
375
		/* actual */
376
377
		$actualArray = $helperOption->getGroupArray();
378
379
		/* compare */
380
381
		$this->assertEquals($expectArray['group'], $actualArray);
382
	}
383
}
384