1
|
|
|
<?php |
2
|
|
|
namespace FwlibTest\Web; |
3
|
|
|
|
4
|
|
|
use Fwlib\Web\HtmlHelper; |
5
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @copyright Copyright 2015 Fwolf |
9
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html LGPL-3.0+ |
10
|
|
|
*/ |
11
|
|
|
class HtmlHelperTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @return MockObject | HtmlHelper |
15
|
|
|
*/ |
16
|
|
|
protected function buildMock() |
17
|
|
|
{ |
18
|
|
|
$mock = $this->getMockBuilder(HtmlHelper::class) |
19
|
|
|
->disableOriginalConstructor() |
20
|
|
|
->setMethods(null) |
21
|
|
|
->getMock(); |
22
|
|
|
|
23
|
|
|
return $mock; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
View Code Duplication |
public function testSetGetCss() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$helper = $this->buildMock(); |
30
|
|
|
|
31
|
|
|
$helper->addCss('foo', 'path/foo/'); |
32
|
|
|
$helper->addCss('bar', 'path/bar/'); |
33
|
|
|
$this->assertEquals(2, count($helper->getCss())); |
34
|
|
|
$this->assertEquals('path/foo/', $helper->getCss('foo')['href']); |
35
|
|
|
|
36
|
|
|
$helper->removeCss('bar'); |
37
|
|
|
$this->assertEquals(1, count($helper->getCss())); |
38
|
|
|
|
39
|
|
|
$helper->clearCss(); |
40
|
|
|
$this->assertEmpty($helper->getCss('foo')); |
41
|
|
|
$this->assertEmpty($helper->getCss()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
View Code Duplication |
public function testSetGetJs() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$helper = $this->buildMock(); |
48
|
|
|
|
49
|
|
|
$helper->addJs('foo', 'path/foo/'); |
50
|
|
|
$helper->addJs('bar', 'path/bar/'); |
51
|
|
|
$this->assertEquals(2, count($helper->getJs())); |
52
|
|
|
$this->assertEquals('path/foo/', $helper->getJs('foo')); |
53
|
|
|
|
54
|
|
|
$helper->removeJs('bar'); |
55
|
|
|
$this->assertEquals(1, count($helper->getJs())); |
56
|
|
|
|
57
|
|
|
$helper->clearJs(); |
58
|
|
|
$this->assertEmpty($helper->getJs('foo')); |
59
|
|
|
$this->assertEmpty($helper->getJs()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function testSetGetRootPath() |
64
|
|
|
{ |
65
|
|
|
$helper = $this->buildMock(); |
66
|
|
|
|
67
|
|
|
$rootPath = 'foo/bar/'; |
68
|
|
|
$helper->setRootPath($rootPath); |
69
|
|
|
$this->assertEquals($rootPath, $helper->getRootPath()); |
70
|
|
|
|
71
|
|
|
$helper->setRootPath('bar/foo'); |
72
|
|
|
$this->assertEquals('bar/foo/', $helper->getRootPath()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.