Completed
Push — master ( c77e24...dd79db )
by Shcherbak
32:18 queued 30:11
created

HtmlTest::testAddClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
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