Completed
Push — master ( 858dca...453367 )
by Henry
06:29
created

OptionTest::testGetLocaleArray()   A

Complexity

Conditions 2
Paths 2

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 2
nc 2
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
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();
0 ignored issues
show
Bug introduced by
The method getOptionArray() does not seem to exist on object<Redaxscript\Tests...View\Helper\OptionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
		$installer = $this->installerFactory();
0 ignored issues
show
Bug introduced by
The method installerFactory() does not seem to exist on object<Redaxscript\Tests...View\Helper\OptionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
		$installer->init();
36
		$installer->rawCreate();
37
		$installer->insertSettings($optionArray);
38
		$installer->rawMigrate();
39
		Db::forTablePrefix('articles')
40
			->create()
41
			->set(
42
			[
43
				'title' => 'Article One',
44
				'alias' => 'article-one'
45
			])
46
			->save();
47
		Db::forTablePrefix('articles')
48
			->create()
49
			->set(
50
			[
51
				'title' => 'Article Two',
52
				'alias' => 'article-two'
53
			])
54
			->save();
55
		Db::forTablePrefix('articles')
56
			->create()
57
			->set(
58
			[
59
				'title' => 'Article Three',
60
				'alias' => 'article-three'
61
			])
62
			->save();
63
		Db::forTablePrefix('groups')
64
			->create()
65
			->set(
66
			[
67
				'name' => 'Group One',
68
				'alias' => 'group-one'
69
			])
70
			->save();
71
		Db::forTablePrefix('groups')
72
			->create()
73
			->set(
74
			[
75
				'name' => 'Group Two',
76
				'alias' => 'group-two'
77
			])
78
			->save();
79
	}
80
81
	/**
82
	 * tearDown
83
	 *
84
	 * @since 3.1.0
85
	 */
86
87
	public function tearDown() : void
88
	{
89
		$this->dropDatabase();
0 ignored issues
show
Bug introduced by
The method dropDatabase() does not seem to exist on object<Redaxscript\Tests...View\Helper\OptionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
	}
91
92
	/**
93
	 * testGetRobotArray
94
	 *
95
	 * @since 3.0.0
96
	 *
97
	 * @param array $expectArray
98
	 *
99
	 * @dataProvider providerAutoloader
100
	 */
101
102
	public function testGetRobotArray(array $expectArray = []) : void
103
	{
104
		/* setup */
105
106
		$helperOption = new Helper\Option($this->_language);
107
108
		/* actual */
109
110
		$actualArray = $helperOption->getRobotArray();
111
112
		/* compare */
113
114
		$this->assertEquals($expectArray['robot'], $actualArray);
115
	}
116
117
	/**
118
	 * testGetCharsetArray
119
	 *
120
	 * @since 4.4.0
121
	 */
122
123
	public function testGetCharsetArray() : void
124
	{
125
		/* setup */
126
127
		$helperOption = new Helper\Option($this->_language);
128
129
		/* actual */
130
131
		$actualArray = $helperOption->getCharsetArray();
132
133
		/* compare */
134
135
		$this->assertContains('UTF-8', $actualArray);
136
	}
137
138
	/**
139
	 * testGetLocaleArray
140
	 *
141
	 * @since 4.4.0
142
	 */
143
144
	public function testGetLocaleArray() : void
145
	{
146
		/* setup */
147
148
		$helperOption = new Helper\Option($this->_language);
149
150
		/* actual */
151
152
		$actualArray = $helperOption->getLocaleArray();
153
154
		/* compare */
155
156
		function_exists('resourcebundle_locales') ? $this->assertContains('en_US', $actualArray) : $this->assertEmpty($actualArray);
157
	}
158
159
	/**
160
	 * testGetZoneArray
161
	 *
162
	 * @since 4.0.0
163
	 */
164
165
	public function testGetZoneArray() : void
166
	{
167
		/* setup */
168
169
		$helperOption = new Helper\Option($this->_language);
170
171
		/* actual */
172
173
		$actualArray = $helperOption->getZoneArray();
174
175
		/* compare */
176
177
		$this->assertContains('UTC', $actualArray);
178
	}
179
180
	/**
181
	 * testGetTimeArray
182
	 *
183
	 * @since 3.0.0
184
	 *
185
	 * @param array $expectArray
186
	 *
187
	 * @dataProvider providerAutoloader
188
	 */
189
190
	public function testGetTimeArray(array $expectArray = []) : void
191
	{
192
		/* setup */
193
194
		$helperOption = new Helper\Option($this->_language);
195
196
		/* actual */
197
198
		$actualArray = $helperOption->getTimeArray();
199
200
		/* compare */
201
202
		$this->assertEquals($expectArray['time'], $actualArray);
203
	}
204
205
	/**
206
	 * testGetDateArray
207
	 *
208
	 * @since 3.0.0
209
	 *
210
	 * @param array $expectArray
211
	 *
212
	 * @dataProvider providerAutoloader
213
	 */
214
215
	public function testGetDateArray(array $expectArray = []) : void
216
	{
217
		/* setup */
218
219
		$helperOption = new Helper\Option($this->_language);
220
221
		/* actual */
222
223
		$actualArray = $helperOption->getDateArray();
224
225
		/* compare */
226
227
		$this->assertEquals($expectArray['date'], $actualArray);
228
	}
229
230
	/**
231
	 * testGetOrderArray
232
	 *
233
	 * @since 3.0.0
234
	 *
235
	 * @param array $expectArray
236
	 *
237
	 * @dataProvider providerAutoloader
238
	 */
239
240
	public function testGetOrderArray(array $expectArray = []) : void
241
	{
242
		/* setup */
243
244
		$helperOption = new Helper\Option($this->_language);
245
246
		/* actual */
247
248
		$actualArray = $helperOption->getOrderArray();
249
250
		/* compare */
251
252
		$this->assertEquals($expectArray['order'], $actualArray);
253
	}
254
255
	/**
256
	 * testGetCaptchaArray
257
	 *
258
	 * @since 3.0.0
259
	 *
260
	 * @param array $expectArray
261
	 *
262
	 * @dataProvider providerAutoloader
263
	 */
264
265
	public function testGetCaptchaArray(array $expectArray = []) : void
266
	{
267
		/* setup */
268
269
		$helperOption = new Helper\Option($this->_language);
270
271
		/* actual */
272
273
		$actualArray = $helperOption->getCaptchaArray();
274
275
		/* compare */
276
277
		$this->assertEquals($expectArray['captcha'], $actualArray);
278
	}
279
280
	/**
281
	 * testGetPermissionArray
282
	 *
283
	 * @since 3.0.0
284
	 *
285
	 * @param array $expectArray
286
	 *
287
	 * @dataProvider providerAutoloader
288
	 */
289
290
	public function testGetPermissionArray(array $expectArray = []) : void
291
	{
292
		/* setup */
293
294
		$helperOption = new Helper\Option($this->_language);
295
296
		/* actual */
297
298
		$actualArray =
299
		[
300
			'content' => $helperOption->getPermissionArray(),
301
			'module' => $helperOption->getPermissionArray('modules'),
302
			'setting' => $helperOption->getPermissionArray('settings')
303
		];
304
305
		/* compare */
306
307
		$this->assertEquals($expectArray['permission']['content'], $actualArray['content']);
308
		$this->assertEquals($expectArray['permission']['module'], $actualArray['module']);
309
		$this->assertEquals($expectArray['permission']['setting'], $actualArray['setting']);
310
	}
311
312
	/**
313
	 * testGetLanguageArray
314
	 *
315
	 * @since 3.0.0
316
	 *
317
	 * @param array $expectArray
318
	 *
319
	 * @dataProvider providerAutoloader
320
	 */
321
322
	public function testGetLanguageArray(array $expectArray = []) : void
323
	{
324
		/* setup */
325
326
		$helperOption = new Helper\Option($this->_language);
327
328
		/* actual */
329
330
		$actualArray = $helperOption->getLanguageArray();
331
332
		/* compare */
333
334
		$this->assertNotTrue(array_diff($expectArray['language'], $actualArray));
335
	}
336
337
	/**
338
	 * testGetTemplateArray
339
	 *
340
	 * @since 3.0.0
341
	 *
342
	 * @param array $expectArray
343
	 *
344
	 * @dataProvider providerAutoloader
345
	 */
346
347
	public function testGetTemplateArray(array $expectArray = []) : void
348
	{
349
		/* setup */
350
351
		$helperOption = new Helper\Option($this->_language);
352
353
		/* actual */
354
355
		$actualArray = $helperOption->getTemplateArray();
356
357
		/* compare */
358
359
		$this->assertNotTrue(array_diff($expectArray['template'], $actualArray));
360
	}
361
362
	/**
363
	 * testGetGroupArray
364
	 *
365
	 * @since 3.0.0
366
	 *
367
	 * @param array $expectArray
368
	 *
369
	 * @dataProvider providerAutoloader
370
	 */
371
372
	public function testGetGroupArray(array $expectArray = []) : void
373
	{
374
		/* setup */
375
376
		$helperOption = new Helper\Option($this->_language);
377
378
		/* actual */
379
380
		$actualArray = $helperOption->getGroupArray();
381
382
		/* compare */
383
384
		$this->assertEquals($expectArray['group'], $actualArray);
385
	}
386
}
387