1
|
|
|
<?php |
2
|
|
|
namespace FwlibTest\Bridge; |
3
|
|
|
|
4
|
|
|
use Fwlib\Bridge\Smarty; |
5
|
|
|
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @copyright Copyright 2013-2015 Fwolf |
9
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html LGPL-3.0+ |
10
|
|
|
*/ |
11
|
|
|
class SmartyTest extends PHPUnitTestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @return Smarty |
15
|
|
|
*/ |
16
|
|
|
protected function buildMock() |
17
|
|
|
{ |
18
|
|
|
return new Smarty; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
|
22
|
|
View Code Duplication |
public function testAddConfigDirPrepend() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$smarty = $this->buildMock(); |
25
|
|
|
|
26
|
|
|
$dir = $smarty->getConfigDir(); |
27
|
|
|
$dirCount = count($dir); |
28
|
|
|
|
29
|
|
|
$smarty->addConfigDirPrepend('foo/'); |
30
|
|
|
|
31
|
|
|
$dir = $smarty->getConfigDir(); |
32
|
|
|
$this->assertEquals($dirCount + 1, count($dir)); |
33
|
|
|
$this->assertEquals('foo/', $dir['']); |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
// Add again to check key overwrite |
37
|
|
|
$smarty->addConfigDirPrepend('bar/'); |
38
|
|
|
$dir = $smarty->getConfigDir(); |
39
|
|
|
$this->assertEquals('bar/', $dir['']); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
View Code Duplication |
public function testAddPluginsDirPrepend() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$smarty = $this->buildMock(); |
46
|
|
|
|
47
|
|
|
$dir = $smarty->getPluginsDir(); |
48
|
|
|
$dirCount = count($dir); |
49
|
|
|
|
50
|
|
|
$smarty->addPluginsDirPrepend('foo/'); |
51
|
|
|
|
52
|
|
|
$dir = $smarty->getPluginsDir(); |
53
|
|
|
$this->assertEquals($dirCount + 1, count($dir)); |
54
|
|
|
$this->assertEquals('foo/', $dir['']); |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
// Add again to check key overwrite |
58
|
|
|
$smarty->addPluginsDirPrepend('bar/'); |
59
|
|
|
$dir = $smarty->getPluginsDir(); |
60
|
|
|
$this->assertEquals('bar/', $dir['']); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
View Code Duplication |
public function testAddTemplateDirPrepend() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$smarty = $this->buildMock(); |
67
|
|
|
|
68
|
|
|
$dir = $smarty->getTemplateDir(); |
69
|
|
|
$dirCount = count($dir); |
70
|
|
|
|
71
|
|
|
$smarty->addTemplateDirPrepend('foo/'); |
72
|
|
|
|
73
|
|
|
$dir = $smarty->getTemplateDir(); |
74
|
|
|
$this->assertEquals($dirCount + 1, count($dir)); |
75
|
|
|
$this->assertEquals('foo/', $dir['']); |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
// Add again to check key overwrite |
79
|
|
|
$smarty->addTemplateDirPrepend('bar/'); |
80
|
|
|
$dir = $smarty->getTemplateDir(); |
81
|
|
|
$this->assertEquals('bar/', $dir['']); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.