1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Fiv\Form\Element; |
4
|
|
|
|
5
|
|
|
use Fiv\Form\Element\Html; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Ivan Shcherbak <[email protected]> 9/17/14 |
9
|
|
|
*/ |
10
|
|
|
class HtmlTest extends \PHPUnit_Framework_TestCase { |
11
|
|
|
|
12
|
|
|
public function testAddClass() { |
13
|
|
|
$htmlElement = new \Fiv\Form\Element\Html(); |
14
|
|
|
|
15
|
|
|
$currentClassName = $htmlElement->getAttribute('class'); |
16
|
|
|
|
17
|
|
|
$this->assertEmpty($currentClassName); |
18
|
|
|
|
19
|
|
|
$htmlElement->addClass('test'); |
20
|
|
|
$this->assertEquals('test', $htmlElement->getAttribute('class')); |
21
|
|
|
|
22
|
|
|
$htmlElement->setAttribute('class', ''); |
23
|
|
|
$this->assertEmpty($htmlElement->getAttribute('class')); |
24
|
|
|
|
25
|
|
|
$htmlElement->setAttribute('class', 'custom_class'); |
26
|
|
|
$this->assertEquals("custom_class", $htmlElement->getAttribute('class')); |
27
|
|
|
|
28
|
|
|
$htmlElement->addClass('other_class'); |
29
|
|
|
$this->assertEquals('custom_class other_class', $htmlElement->getAttribute('class')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function testTag() { |
34
|
|
|
|
35
|
|
|
$imgHtml = \Fiv\Form\Element\Html::tag('img', [ |
36
|
|
|
'src' => "/images/logo.png", |
37
|
|
|
'title' => "logo", |
38
|
|
|
]); |
39
|
|
|
|
40
|
|
|
$this->assertTrue((boolean) preg_match("!/>!", $imgHtml)); |
41
|
|
|
$this->assertTrue((boolean) preg_match("!title=!", $imgHtml)); |
42
|
|
|
$this->assertTrue((boolean) preg_match("!src=!", $imgHtml)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testAttributes() { |
47
|
|
|
|
48
|
|
|
$tag = new Html(); |
49
|
|
|
$tag->setTag('input'); |
50
|
|
|
$tag->setAttributes([ |
51
|
|
|
'value' => 123, |
52
|
|
|
]); |
53
|
|
|
$tag->addClass('test'); |
54
|
|
|
$tag->addClass('other'); |
55
|
|
|
|
56
|
|
|
$this->assertEquals(['value' => 123, 'class' => 'test other'], $tag->getAttributes()); |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|