Completed
Push — master ( 16ddfb...0ea243 )
by Henry
09:18
created

tests/unit/Template/HelperTest.php (6 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Tests\Template;
3
4
use Redaxscript\Db;
5
use Redaxscript\Template;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * HelperTest
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 * @author Balázs Szilágyi
17
 *
18
 * @covers Redaxscript\Template\Helper
19
 * @covers Redaxscript\Template\Helper\Canonical
20
 * @covers Redaxscript\Template\Helper\Client
21
 * @covers Redaxscript\Template\Helper\Description
22
 * @covers Redaxscript\Template\Helper\Direction
23
 * @covers Redaxscript\Template\Helper\HelperAbstract
24
 * @covers Redaxscript\Template\Helper\Keywords
25
 * @covers Redaxscript\Template\Helper\Robots
26
 * @covers Redaxscript\Template\Helper\Subset
27
 * @covers Redaxscript\Template\Helper\Title
28
 */
29
30
class HelperTest extends TestCaseAbstract
31
{
32
	/**
33
	 * setUp
34
	 *
35
	 * @since 3.1.0
36
	 */
37
38
	public function setUp() : void
39
	{
40
		parent::setUp();
41
		$optionArray =
42
		[
43
			'adminName' => 'Test',
44
			'adminUser' => 'test',
45
			'adminPassword' => 'test',
46
			'adminEmail' => '[email protected]'
47
		];
48
		$installer = $this->installerFactory();
0 ignored issues
show
The method installerFactory() does not seem to exist on object<Redaxscript\Tests\Template\HelperTest>.

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...
49
		$installer->init();
50
		$installer->rawCreate();
51
		$installer->insertSettings($optionArray);
52
		$categoryOne = Db::forTablePrefix('categories')->create();
53
		$categoryOne
54
			->set(
55
			[
56
				'title' => 'Category One',
57
				'alias' => 'category-one'
58
			])
59
			->save();
60
		$categoryTwo = Db::forTablePrefix('categories')->create();
61
		$categoryTwo
62
			->set(
63
			[
64
				'title' => 'Category Two',
65
				'alias' => 'category-two',
66
				'description' => 'Category Two',
67
				'keywords' => 'Category Two',
68
				'robots' => 1
69
			])
70
			->save();
71
		$categoryThree = Db::forTablePrefix('categories')->create();
72
		$categoryThree
73
			->set(
74
			[
75
				'title' => 'Category Three',
76
				'alias' => 'category-three',
77
				'parent' => $categoryTwo->id
78
			])
79
			->save();
80
		Db::forTablePrefix('articles')
81
			->create()
82
			->set(
83
			[
84
				'title' => 'Article One',
85
				'alias' => 'article-one',
86
				'category' => $categoryOne->id
87
			])
88
			->save();
89
		Db::forTablePrefix('articles')
90
			->create()
91
			->set(
92
			[
93
				'title' => 'Article Two',
94
				'alias' => 'article-two',
95
				'description' => 'Article Two',
96
				'keywords' => 'Article Two',
97
				'robots' => 0,
98
				'category' => $categoryTwo->id
99
			])
100
			->save();
101
		Db::forTablePrefix('articles')
102
			->create()
103
			->set(
104
			[
105
				'title' => 'Article Three',
106
				'alias' => 'article-three',
107
				'category' => $categoryTwo->id
108
			])
109
			->save();
110
		Db::forTablePrefix('articles')
111
			->create()
112
			->set(
113
			[
114
				'title' => 'Article Four',
115
				'alias' => 'article-four',
116
				'category' => $categoryThree->id
117
			])
118
			->save();
119
	}
120
121
	/**
122
	 * tearDown
123
	 *
124
	 * @since 3.1.0
125
	 */
126
127
	public function tearDown() : void
128
	{
129
		$this->dropDatabase();
0 ignored issues
show
The method dropDatabase() does not seem to exist on object<Redaxscript\Tests\Template\HelperTest>.

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...
130
	}
131
132
	/**
133
	 * testGetRegistry
134
	 *
135
	 * @since 2.6.0
136
	 */
137
138
	public function testGetRegistry() : void
139
	{
140
		/* setup */
141
142
		$this->_registry->set('testKey', 'testValue');
143
144
		/* actual */
145
146
		$actual = Template\Helper::getRegistry('testKey');
147
148
		/* compare */
149
150
		$this->assertEquals('testValue', $actual);
151
	}
152
153
	/**
154
	 * testGetLanguage
155
	 *
156
	 * @since 2.6.0
157
	 */
158
159
	public function testGetLanguage() : void
160
	{
161
		/* setup */
162
163
		$this->_language->set('testKey', 'testValue');
164
165
		/* actual */
166
167
		$actual = Template\Helper::getLanguage('testKey');
168
169
		/* compare */
170
171
		$this->assertEquals('testValue', $actual);
172
	}
173
174
	/**
175
	 * testGetSetting
176
	 *
177
	 * @since 2.6.0
178
	 */
179
180
	public function testGetSetting() : void
181
	{
182
		/* actual */
183
184
		$actual = Template\Helper::getSetting('charset');
185
186
		/* compare */
187
188
		$this->assertEquals('utf-8', $actual);
189
	}
190
191
	/**
192
	 * testGetTitle
193
	 *
194
	 * @since 3.0.0
195
	 *
196
	 * @param array $registryArray
197
	 * @param array $settingArray
198
	 * @param string $expect
199
	 *
200
	 * @dataProvider providerAutoloader
201
	 */
202
203
	public function testGetTitle(array $registryArray = [], array $settingArray = [], string $expect = null) : void
204
	{
205
		/* setup */
206
207
		$this->_registry->init($registryArray);
208
		$setting = $this->settingFactory();
0 ignored issues
show
The method settingFactory() does not seem to exist on object<Redaxscript\Tests\Template\HelperTest>.

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...
209
		$setting->set('title', $settingArray['title']);
210
211
		/* actual */
212
213
		$actual = Template\Helper::getTitle();
214
215
		/* compare */
216
217
		$this->assertEquals($expect, $actual);
218
	}
219
220
	/**
221
	 * testGetCanonical
222
	 *
223
	 * @since 3.0.0
224
	 *
225
	 * @param array $registryArray
226
	 * @param string $expect
227
	 *
228
	 * @dataProvider providerAutoloader
229
	 */
230
231
	public function testGetCanonical(array $registryArray = [], string $expect = null) : void
232
	{
233
		/* setup */
234
235
		$this->_registry->init($registryArray);
236
237
		/* actual */
238
239
		$actual = Template\Helper::getCanonical();
240
241
		/* compare */
242
243
		$this->assertEquals($expect, $actual);
244
	}
245
246
	/**
247
	 * testGetDescription
248
	 *
249
	 * @since 3.0.0
250
	 *
251
	 * @param array $registryArray
252
	 * @param array $settingArray
253
	 * @param string $expect
254
	 *
255
	 * @dataProvider providerAutoloader
256
	 */
257
258
	public function testGetDescription(array $registryArray = [], array $settingArray = [], string $expect = null) : void
259
	{
260
		/* setup */
261
262
		$this->_registry->init($registryArray);
263
		$setting = $this->settingFactory();
0 ignored issues
show
The method settingFactory() does not seem to exist on object<Redaxscript\Tests\Template\HelperTest>.

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...
264
		$setting->set('description', $settingArray['description']);
265
266
		/* actual */
267
268
		$actual = Template\Helper::getDescription();
269
270
		/* compare */
271
272
		$this->assertEquals($expect, $actual);
273
	}
274
275
	/**
276
	 * testGetKeywords
277
	 *
278
	 * @since 3.0.0
279
	 *
280
	 * @param array $registryArray
281
	 * @param array $settingArray
282
	 * @param string $expect
283
	 *
284
	 * @dataProvider providerAutoloader
285
	 */
286
287
	public function testGetKeywords(array $registryArray = [], array $settingArray = [], string $expect = null) : void
288
	{
289
		/* setup */
290
291
		$this->_registry->init($registryArray);
292
		$setting = $this->settingFactory();
0 ignored issues
show
The method settingFactory() does not seem to exist on object<Redaxscript\Tests\Template\HelperTest>.

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...
293
		$setting->set('keywords', $settingArray['keywords']);
294
295
		/* actual */
296
297
		$actual = Template\Helper::getKeywords();
298
299
		/* compare */
300
301
		$this->assertEquals($expect, $actual);
302
	}
303
304
	/**
305
	 * testGetRobots
306
	 *
307
	 * @since 3.0.0
308
	 *
309
	 * @param array $registryArray
310
	 * @param array $settingArray
311
	 * @param string $expect
312
	 *
313
	 * @dataProvider providerAutoloader
314
	 */
315
316
	public function testGetRobots(array $registryArray = [], array $settingArray = [], string $expect = null) : void
317
	{
318
		/* setup */
319
320
		$this->_registry->init($registryArray);
321
		$setting = $this->settingFactory();
0 ignored issues
show
The method settingFactory() does not seem to exist on object<Redaxscript\Tests\Template\HelperTest>.

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...
322
		$setting->set('robots', $settingArray['robots']);
323
324
		/* actual */
325
326
		$actual = Template\Helper::getRobots();
327
328
		/* compare */
329
330
		$this->assertEquals($expect, $actual);
331
	}
332
333
	/**
334
	 * testGetTransport
335
	 *
336
	 * @since 3.0.0
337
	 */
338
339
	public function testGetTransport() : void
340
	{
341
		/* actual */
342
343
		$actualArray = Template\Helper::getTransport();
344
345
		/* compare */
346
347
		$this->assertArrayHasKey('baseUrl', $actualArray);
348
		$this->assertArrayHasKey('generator', $actualArray);
349
		$this->assertArrayHasKey('language', $actualArray);
350
		$this->assertArrayHasKey('registry', $actualArray);
351
		$this->assertArrayHasKey('version', $actualArray);
352
	}
353
354
	/**
355
	 * testGetSubset
356
	 *
357
	 * @since 3.0.0
358
	 *
359
	 * @param array $registryArray
360
	 * @param string $expect
361
	 *
362
	 * @dataProvider providerAutoloader
363
	 */
364
365
	public function testGetSubset(array $registryArray = [], string $expect = null) : void
366
	{
367
		/* setup */
368
369
		$this->_registry->init($registryArray);
370
371
		/* actual */
372
373
		$actual = Template\Helper::getSubset();
374
375
		/* compare */
376
377
		$this->assertEquals($expect, $actual);
378
	}
379
380
	/**
381
	 * testGetDirection
382
	 *
383
	 * @since 3.0.0
384
	 *
385
	 * @param array $registryArray
386
	 * @param string $expect
387
	 *
388
	 * @dataProvider providerAutoloader
389
	 */
390
391
	public function testGetDirection(array $registryArray = [], string $expect = null) : void
392
	{
393
		/* setup */
394
395
		$this->_registry->init($registryArray);
396
397
		/* actual */
398
399
		$actual = Template\Helper::getDirection();
400
401
		/* compare */
402
403
		$this->assertEquals($expect, $actual);
404
	}
405
406
	/**
407
	 * testGetClass
408
	 *
409
	 * @since 3.0.0
410
	 *
411
	 * @param array $registryArray
412
	 * @param string $expect
413
	 *
414
	 * @dataProvider providerAutoloader
415
	 */
416
417
	public function testGetClass(array $registryArray = [], string $expect = null) : void
418
	{
419
		/* setup */
420
421
		$this->_registry->init($registryArray);
422
423
		/* actual */
424
425
		$actual = Template\Helper::getClass('rs-is-');
426
427
		/* compare */
428
429
		$this->assertEquals($expect, $actual);
430
	}
431
}
432