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\Title |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
class HelperTest extends TestCaseAbstract |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* setUp |
33
|
|
|
* |
34
|
|
|
* @since 3.1.0 |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
public function setUp() : void |
38
|
|
|
{ |
39
|
|
|
parent::setUp(); |
40
|
|
|
$optionArray = $this->getOptionArray(); |
41
|
|
|
$installer = $this->installerFactory(); |
42
|
|
|
$installer->init(); |
43
|
|
|
$installer->rawCreate(); |
44
|
|
|
$installer->insertSettings($optionArray); |
45
|
|
|
$categoryOne = Db::forTablePrefix('categories')->create(); |
46
|
|
|
$categoryOne |
47
|
|
|
->set( |
48
|
|
|
[ |
49
|
|
|
'title' => 'Category One', |
50
|
|
|
'alias' => 'category-one' |
51
|
|
|
]) |
52
|
|
|
->save(); |
53
|
|
|
$categoryTwo = Db::forTablePrefix('categories')->create(); |
54
|
|
|
$categoryTwo |
55
|
|
|
->set( |
56
|
|
|
[ |
57
|
|
|
'title' => 'Category Two', |
58
|
|
|
'alias' => 'category-two', |
59
|
|
|
'description' => 'Category Two', |
60
|
|
|
'keywords' => 'category, two', |
61
|
|
|
'robots' => 1 |
62
|
|
|
]) |
63
|
|
|
->save(); |
64
|
|
|
$categoryThree = Db::forTablePrefix('categories')->create(); |
65
|
|
|
$categoryThree |
66
|
|
|
->set( |
67
|
|
|
[ |
68
|
|
|
'title' => 'Category Three', |
69
|
|
|
'alias' => 'category-three', |
70
|
|
|
'parent' => $categoryTwo->id |
71
|
|
|
]) |
72
|
|
|
->save(); |
73
|
|
|
Db::forTablePrefix('articles') |
74
|
|
|
->create() |
75
|
|
|
->set( |
76
|
|
|
[ |
77
|
|
|
'title' => 'Article One', |
78
|
|
|
'alias' => 'article-one', |
79
|
|
|
'category' => $categoryOne->id |
80
|
|
|
]) |
81
|
|
|
->save(); |
82
|
|
|
Db::forTablePrefix('articles') |
83
|
|
|
->create() |
84
|
|
|
->set( |
85
|
|
|
[ |
86
|
|
|
'title' => 'Article Two', |
87
|
|
|
'alias' => 'article-two', |
88
|
|
|
'description' => 'Article Two', |
89
|
|
|
'keywords' => 'article, two', |
90
|
|
|
'robots' => 0, |
91
|
|
|
'category' => $categoryTwo->id |
92
|
|
|
]) |
93
|
|
|
->save(); |
94
|
|
|
Db::forTablePrefix('articles') |
95
|
|
|
->create() |
96
|
|
|
->set( |
97
|
|
|
[ |
98
|
|
|
'title' => 'Article Three', |
99
|
|
|
'alias' => 'article-three', |
100
|
|
|
'category' => $categoryTwo->id |
101
|
|
|
]) |
102
|
|
|
->save(); |
103
|
|
|
Db::forTablePrefix('articles') |
104
|
|
|
->create() |
105
|
|
|
->set( |
106
|
|
|
[ |
107
|
|
|
'title' => 'Article Four', |
108
|
|
|
'alias' => 'article-four', |
109
|
|
|
'category' => $categoryThree->id |
110
|
|
|
]) |
111
|
|
|
->save(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* tearDown |
116
|
|
|
* |
117
|
|
|
* @since 3.1.0 |
118
|
|
|
*/ |
119
|
|
|
|
120
|
|
|
public function tearDown() : void |
121
|
|
|
{ |
122
|
|
|
$this->dropDatabase(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* testGetRegistry |
127
|
|
|
* |
128
|
|
|
* @since 2.6.0 |
129
|
|
|
*/ |
130
|
|
|
|
131
|
|
|
public function testGetRegistry() : void |
132
|
|
|
{ |
133
|
|
|
/* setup */ |
134
|
|
|
|
135
|
|
|
$this->_registry->set('testKey', 'testValue'); |
136
|
|
|
|
137
|
|
|
/* actual */ |
138
|
|
|
|
139
|
|
|
$actual = Template\Helper::getRegistry('testKey'); |
140
|
|
|
|
141
|
|
|
/* compare */ |
142
|
|
|
|
143
|
|
|
$this->assertEquals('testValue', $actual); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* testGetLanguage |
148
|
|
|
* |
149
|
|
|
* @since 2.6.0 |
150
|
|
|
*/ |
151
|
|
|
|
152
|
|
|
public function testGetLanguage() : void |
153
|
|
|
{ |
154
|
|
|
/* setup */ |
155
|
|
|
|
156
|
|
|
$this->_language->set('testKey', 'testValue'); |
157
|
|
|
|
158
|
|
|
/* actual */ |
159
|
|
|
|
160
|
|
|
$actual = Template\Helper::getLanguage('testKey'); |
161
|
|
|
|
162
|
|
|
/* compare */ |
163
|
|
|
|
164
|
|
|
$this->assertEquals('testValue', $actual); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* testGetSetting |
169
|
|
|
* |
170
|
|
|
* @since 2.6.0 |
171
|
|
|
*/ |
172
|
|
|
|
173
|
|
|
public function testGetSetting() : void |
174
|
|
|
{ |
175
|
|
|
/* actual */ |
176
|
|
|
|
177
|
|
|
$actual = Template\Helper::getSetting('charset'); |
178
|
|
|
|
179
|
|
|
/* compare */ |
180
|
|
|
|
181
|
|
|
$this->assertEquals('UTF-8', $actual); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* testGetTitle |
186
|
|
|
* |
187
|
|
|
* @since 3.0.0 |
188
|
|
|
* |
189
|
|
|
* @param array $registryArray |
190
|
|
|
* @param array $settingArray |
191
|
|
|
* @param string $expect |
192
|
|
|
* |
193
|
|
|
* @dataProvider providerAutoloader |
194
|
|
|
*/ |
195
|
|
|
|
196
|
|
|
public function testGetTitle(array $registryArray = [], array $settingArray = [], string $expect = null) : void |
197
|
|
|
{ |
198
|
|
|
/* setup */ |
199
|
|
|
|
200
|
|
|
$this->_registry->init($registryArray); |
201
|
|
|
$setting = $this->settingFactory(); |
202
|
|
|
$setting->set('title', $settingArray['title']); |
203
|
|
|
|
204
|
|
|
/* actual */ |
205
|
|
|
|
206
|
|
|
$actual = Template\Helper::getTitle(); |
207
|
|
|
|
208
|
|
|
/* compare */ |
209
|
|
|
|
210
|
|
|
$this->assertEquals($expect, $actual); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* testGetCanonical |
215
|
|
|
* |
216
|
|
|
* @since 3.0.0 |
217
|
|
|
* |
218
|
|
|
* @param array $registryArray |
219
|
|
|
* @param string $expect |
220
|
|
|
* |
221
|
|
|
* @dataProvider providerAutoloader |
222
|
|
|
*/ |
223
|
|
|
|
224
|
|
|
public function testGetCanonical(array $registryArray = [], string $expect = null) : void |
225
|
|
|
{ |
226
|
|
|
/* setup */ |
227
|
|
|
|
228
|
|
|
$this->_registry->init($registryArray); |
229
|
|
|
|
230
|
|
|
/* actual */ |
231
|
|
|
|
232
|
|
|
$actual = Template\Helper::getCanonical(); |
233
|
|
|
|
234
|
|
|
/* compare */ |
235
|
|
|
|
236
|
|
|
$this->assertEquals($expect, $actual); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* testGetDescription |
241
|
|
|
* |
242
|
|
|
* @since 3.0.0 |
243
|
|
|
* |
244
|
|
|
* @param array $registryArray |
245
|
|
|
* @param array $settingArray |
246
|
|
|
* @param string $expect |
247
|
|
|
* |
248
|
|
|
* @dataProvider providerAutoloader |
249
|
|
|
*/ |
250
|
|
|
|
251
|
|
|
public function testGetDescription(array $registryArray = [], array $settingArray = [], string $expect = null) : void |
252
|
|
|
{ |
253
|
|
|
/* setup */ |
254
|
|
|
|
255
|
|
|
$this->_registry->init($registryArray); |
256
|
|
|
$setting = $this->settingFactory(); |
257
|
|
|
$setting->set('description', $settingArray['description']); |
258
|
|
|
|
259
|
|
|
/* actual */ |
260
|
|
|
|
261
|
|
|
$actual = Template\Helper::getDescription(); |
262
|
|
|
|
263
|
|
|
/* compare */ |
264
|
|
|
|
265
|
|
|
$this->assertEquals($expect, $actual); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* testGetKeywords |
270
|
|
|
* |
271
|
|
|
* @since 3.0.0 |
272
|
|
|
* |
273
|
|
|
* @param array $registryArray |
274
|
|
|
* @param array $settingArray |
275
|
|
|
* @param string $expect |
276
|
|
|
* |
277
|
|
|
* @dataProvider providerAutoloader |
278
|
|
|
*/ |
279
|
|
|
|
280
|
|
|
public function testGetKeywords(array $registryArray = [], array $settingArray = [], string $expect = null) : void |
281
|
|
|
{ |
282
|
|
|
/* setup */ |
283
|
|
|
|
284
|
|
|
$this->_registry->init($registryArray); |
285
|
|
|
$setting = $this->settingFactory(); |
286
|
|
|
$setting->set('keywords', $settingArray['keywords']); |
287
|
|
|
|
288
|
|
|
/* actual */ |
289
|
|
|
|
290
|
|
|
$actual = Template\Helper::getKeywords(); |
291
|
|
|
|
292
|
|
|
/* compare */ |
293
|
|
|
|
294
|
|
|
$this->assertEquals($expect, $actual); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* testGetRobots |
299
|
|
|
* |
300
|
|
|
* @since 3.0.0 |
301
|
|
|
* |
302
|
|
|
* @param array $registryArray |
303
|
|
|
* @param array $settingArray |
304
|
|
|
* @param string $expect |
305
|
|
|
* |
306
|
|
|
* @dataProvider providerAutoloader |
307
|
|
|
*/ |
308
|
|
|
|
309
|
|
|
public function testGetRobots(array $registryArray = [], array $settingArray = [], string $expect = null) : void |
310
|
|
|
{ |
311
|
|
|
/* setup */ |
312
|
|
|
|
313
|
|
|
$this->_registry->init($registryArray); |
314
|
|
|
$setting = $this->settingFactory(); |
315
|
|
|
$setting->set('robots', $settingArray['robots']); |
316
|
|
|
|
317
|
|
|
/* actual */ |
318
|
|
|
|
319
|
|
|
$actual = Template\Helper::getRobots(); |
320
|
|
|
|
321
|
|
|
/* compare */ |
322
|
|
|
|
323
|
|
|
$this->assertEquals($expect, $actual); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* testGetTransport |
328
|
|
|
* |
329
|
|
|
* @since 3.0.0 |
330
|
|
|
*/ |
331
|
|
|
|
332
|
|
|
public function testGetTransport() : void |
333
|
|
|
{ |
334
|
|
|
/* actual */ |
335
|
|
|
|
336
|
|
|
$actualArray = Template\Helper::getTransport(); |
337
|
|
|
|
338
|
|
|
/* compare */ |
339
|
|
|
|
340
|
|
|
$this->assertArrayHasKey('baseUrl', $actualArray); |
341
|
|
|
$this->assertArrayHasKey('generator', $actualArray); |
342
|
|
|
$this->assertArrayHasKey('language', $actualArray); |
343
|
|
|
$this->assertArrayHasKey('registry', $actualArray); |
344
|
|
|
$this->assertArrayHasKey('version', $actualArray); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* testGetDirection |
349
|
|
|
* |
350
|
|
|
* @since 3.0.0 |
351
|
|
|
* |
352
|
|
|
* @param array $registryArray |
353
|
|
|
* @param string $expect |
354
|
|
|
* |
355
|
|
|
* @dataProvider providerAutoloader |
356
|
|
|
*/ |
357
|
|
|
|
358
|
|
|
public function testGetDirection(array $registryArray = [], string $expect = null) : void |
359
|
|
|
{ |
360
|
|
|
/* setup */ |
361
|
|
|
|
362
|
|
|
$this->_registry->init($registryArray); |
363
|
|
|
|
364
|
|
|
/* actual */ |
365
|
|
|
|
366
|
|
|
$actual = Template\Helper::getDirection(); |
367
|
|
|
|
368
|
|
|
/* compare */ |
369
|
|
|
|
370
|
|
|
$this->assertEquals($expect, $actual); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* testGetClass |
375
|
|
|
* |
376
|
|
|
* @since 3.0.0 |
377
|
|
|
* |
378
|
|
|
* @param array $registryArray |
379
|
|
|
* @param string $expect |
380
|
|
|
* |
381
|
|
|
* @dataProvider providerAutoloader |
382
|
|
|
*/ |
383
|
|
|
|
384
|
|
|
public function testGetClass(array $registryArray = [], string $expect = null) : void |
385
|
|
|
{ |
386
|
|
|
/* setup */ |
387
|
|
|
|
388
|
|
|
$this->_registry->init($registryArray); |
389
|
|
|
|
390
|
|
|
/* actual */ |
391
|
|
|
|
392
|
|
|
$actual = Template\Helper::getClass('rs-is-'); |
393
|
|
|
|
394
|
|
|
/* compare */ |
395
|
|
|
|
396
|
|
|
$this->assertEquals($expect, $actual); |
397
|
|
|
} |
398
|
|
|
} |
399
|
|
|
|