Completed
Branchmaster (8f7741)
created

HelperTest::setUpBeforeClass()   A

↳ Parent: HelperTest

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 68
Code Lines 56

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 9.2447
c 0
b 0
f 0
cc 1
eloc 56
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Redaxscript\Tests\Template;
3
4
use Redaxscript\Db;
5
use Redaxscript\Registry;
6
use Redaxscript\Template;
7
use Redaxscript\Tests\TestCaseAbstract;
8
9
/**
10
 * HelperTest
11
 *
12
 * @since 3.0.0
13
 *
14
 * @package Redaxscript
15
 * @category Tests
16
 * @author Henry Ruhs
17
 * @author Balázs Szilágyi
18
 */
19
20
class HelperTest extends TestCaseAbstract
21
{
22
	/**
23
	 * instance of the registry class
24
	 *
25
	 * @var object
26
	 */
27
28
	protected $_registry;
29
30
	/**
31
	 * setUp
32
	 *
33
	 * @since 3.0.0
34
	 */
35
36
	public function setUp()
37
	{
38
		$this->_registry = Registry::getInstance();
39
	}
40
41
	/**
42
	 * setUpBeforeClass
43
	 *
44
	 * @since 3.0.0
45
	 */
46
47
	public static function setUpBeforeClass()
48
	{
49
		Db::forTablePrefix('categories')
50
			->create()
51
			->set(
52
			[
53
				'id' => 2,
54
				'title' => 'test',
55
				'alias' => 'test-one',
56
				'author' => 'test',
57
				'description' => 'category-description',
58
				'keywords' => 'category-keywords',
59
				'robots' => 5
60
			])
61
			->save();
62
		Db::forTablePrefix('categories')
63
			->create()
64
			->set(
65
			[
66
				'id' => 3,
67
				'title' => 'test',
68
				'alias' => 'test-two',
69
				'author' => 'test',
70
				'parent' => 2
71
			])
72
			->save();
73
		Db::forTablePrefix('articles')
74
			->create()
75
			->set(
76
			[
77
				'id' => 2,
78
				'title' => 'test',
79
				'alias' => 'test-three',
80
				'author' => 'test',
81
				'description' => 'article-description',
82
				'keywords' => 'article-keywords',
83
				'robots' => 4,
84
				'text' => 'test',
85
				'category' => 2
86
			])
87
			->save();
88
		Db::forTablePrefix('articles')
89
			->create()
90
			->set(
91
			[
92
				'id' => 3,
93
				'title' => 'test',
94
				'alias' => 'test-four',
95
				'author' => 'test',
96
				'text' => 'test',
97
				'category' => 2
98
			])
99
			->save();
100
		Db::forTablePrefix('articles')
101
			->create()
102
			->set(
103
			[
104
				'id' => 4,
105
				'title' => 'test',
106
				'alias' => 'test-five',
107
				'author' => 'test',
108
				'text' => 'test',
109
				'category' => 3
110
			])
111
			->save();
112
		Db::setSetting('description', 'setting-description');
113
		Db::setSetting('keywords', 'setting-keywords');
114
	}
115
116
	/**
117
	 * tearDownAfterClass
118
	 *
119
	 * @since 3.0.0
120
	 */
121
122
	public static function tearDownAfterClass()
123
	{
124
		Db::forTablePrefix('categories')->whereNotEqual('id', 1)->deleteMany();
125
		Db::forTablePrefix('articles')->whereNotEqual('id', 1)->deleteMany();
126
	}
127
128
	/**
129
	 * providerGetCanonical
130
	 *
131
	 * @since 3.0.0
132
	 *
133
	 * @return array
134
	 */
135
136
	public function providerGetCanonical()
137
	{
138
		return $this->getProvider('tests/provider/Template/helper_get_canonical.json');
139
	}
140
141
	/**
142
	 * providerGetDescription
143
	 *
144
	 * @since 3.0.0
145
	 *
146
	 * @return array
147
	 */
148
149
	public function providerGetDescription()
150
	{
151
		return $this->getProvider('tests/provider/Template/helper_get_description.json');
152
	}
153
154
	/**
155
	 * providerGetKeywords
156
	 *
157
	 * @since 3.0.0
158
	 *
159
	 * @return array
160
	 */
161
162
	public function providerGetKeywords()
163
	{
164
		return $this->getProvider('tests/provider/Template/helper_get_keywords.json');
165
	}
166
167
	/**
168
	 * providerGetRobots
169
	 *
170
	 * @since 3.0.0
171
	 *
172
	 * @return array
173
	 */
174
175
	public function providerGetRobots()
176
	{
177
		return $this->getProvider('tests/provider/Template/helper_get_robots.json');
178
	}
179
180
	/**
181
	 * providerGetSubset
182
	 *
183
	 * @since 3.0.0
184
	 *
185
	 * @return array
186
	 */
187
188
	public function providerGetSubset()
189
	{
190
		return $this->getProvider('tests/provider/Template/helper_get_subset.json');
191
	}
192
193
	/**
194
	 * providerGetDirection
195
	 *
196
	 * @since 3.0.0
197
	 *
198
	 * @return array
199
	 */
200
201
	public function providerGetDirection()
202
	{
203
		return $this->getProvider('tests/provider/Template/helper_get_direction.json');
204
	}
205
206
	/**
207
	 * providerGetDirection
208
	 *
209
	 * @since 3.0.0
210
	 *
211
	 * @return array
212
	 */
213
214
	public function providerGetClass()
215
	{
216
		return $this->getProvider('tests/provider/Template/helper_get_class.json');
217
	}
218
219
	/**
220
	 * testGetCanonical
221
	 *
222
	 * @since 3.0.0
223
	 *
224
	 * @param array $registryArray
225
	 * @param string $expect
226
	 *
227
	 * @dataProvider providerGetCanonical
228
	 */
229
230
	public function testCanonical($registryArray = [], $expect = null)
231
	{
232
		/* setup */
233
234
		$this->_registry->init($registryArray);
235
236
		/* actual */
237
238
		$actual = Template\Helper::getCanonical();
239
240
		/* compare */
241
242
		$this->assertEquals($expect, $actual);
243
	}
244
245
	/**
246
	 * testGetDescription
247
	 *
248
	 * @since 3.0.0
249
	 *
250
	 * @param array $registryArray
251
	 * @param string $expect
252
	 *
253
	 * @dataProvider providerGetDescription
254
	 */
255
256
	public function testGetDescription($registryArray = [], $expect = null)
257
	{
258
		/* setup */
259
260
		$this->_registry->init($registryArray);
261
262
		/* actual */
263
264
		$actual = Template\Helper::getDescription();
265
266
		/* compare */
267
268
		$this->assertEquals($expect, $actual);
269
	}
270
271
	/**
272
	 * testGetKeywords
273
	 *
274
	 * @since 3.0.0
275
	 *
276
	 * @param array $registryArray
277
	 * @param string $expect
278
	 *
279
	 * @dataProvider providerGetKeywords
280
	 */
281
282
	public function testGetKeywords($registryArray = [], $expect = null)
283
	{
284
		/* setup */
285
286
		$this->_registry->init($registryArray);
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 string $expect
304
	 *
305
	 * @dataProvider providerGetRobots
306
	 */
307
308
	public function testGetRobots($registryArray = [], $expect = null)
309
	{
310
		/* setup */
311
312
		$this->_registry->init($registryArray);
313
314
		/* actual */
315
316
		$actual = Template\Helper::getRobots();
317
318
		/* compare */
319
320
		$this->assertEquals($expect, $actual);
321
	}
322
323
	/**
324
	 * testGetTransport
325
	 *
326
	 * @since 3.0.0
327
	 */
328
329
	public function testGetTransport()
330
	{
331
		/* actual */
332
333
		$actualArray = Template\Helper::getTransport();
334
335
		/* compare */
336
337
		$this->assertArrayHasKey('baseURL', $actualArray);
338
		$this->assertArrayHasKey('generator', $actualArray);
339
		$this->assertArrayHasKey('language', $actualArray);
340
		$this->assertArrayHasKey('registry', $actualArray);
341
		$this->assertArrayHasKey('version', $actualArray);
342
	}
343
344
	/**
345
	 * testGetSubset
346
	 *
347
	 * @since 3.0.0
348
	 *
349
	 * @param array $registryArray
350
	 * @param string $expect
351
	 *
352
	 * @dataProvider providerGetSubset
353
	 */
354
355
	public function testGetSubset($registryArray = [], $expect = null)
356
	{
357
		/* setup */
358
359
		$this->_registry->init($registryArray);
360
361
		/* actual */
362
363
		$actual = Template\Helper::getSubset();
364
365
		/* compare */
366
367
		$this->assertEquals($expect, $actual);
368
	}
369
370
	/**
371
	 * testGetDirection
372
	 *
373
	 * @since 3.0.0
374
	 *
375
	 * @param array $registryArray
376
	 * @param string $expect
377
	 *
378
	 * @dataProvider providerGetDirection
379
	 */
380
381
	public function testGetDirection($registryArray = [], $expect = null)
382
	{
383
		/* setup */
384
385
		$this->_registry->init($registryArray);
386
387
		/* actual */
388
389
		$actual = Template\Helper::getDirection();
390
391
		/* compare */
392
393
		$this->assertEquals($expect, $actual);
394
	}
395
396
	/**
397
	 * testGetClass
398
	 *
399
	 * @since 3.0.0
400
	 *
401
	 * @param array $registryArray
402
	 * @param string $expect
403
	 *
404
	 * @dataProvider providerGetClass
405
	 */
406
407
	public function testGetClass($registryArray = [], $expect = null)
408
	{
409
		/* setup */
410
411
		$this->_registry->init($registryArray);
412
413
		/* actual */
414
415
		$actual = Template\Helper::getClass();
416
417
		/* compare */
418
419
		$this->assertEquals($expect, $actual);
420
	}
421
}
422