Completed
Push — master ( 4d87e8...6f96cd )
by Henry
06:30
created

OptionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

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