Passed
Push — master ( efa86f...55c9f6 )
by Petr
10:18
created

AttributeTest::testExtend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 22
rs 9.7333
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BasicTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_templates\HtmlElement\TAttributes;
8
9
10
/**
11
 * Class AttributeTest
12
 * @package BasicTests
13
 * How to check traits? Extend them.
14
 */
15
class AttributeTest extends CommonTestClass
16
{
17
    public function testSimple()
18
    {
19
        $data = new Attributes();
20
        $this->assertEmpty($data->getAttributes());
21
        $this->assertEmpty($data->getAttribute('foo'));
22
        $data->setAttribute('foo', 'bar');
23
        $this->assertEquals('bar', $data->getAttribute('foo'));
24
        $data->setAttribute('foo', 'baz');
25
        $this->assertEquals('baz', $data->getAttribute('foo'));
26
        $data->removeAttribute('foo');
27
        $this->assertEmpty($data->getAttribute('foo'));
28
        $this->assertEmpty($data->getAttributes());
29
    }
30
31
    public function testExtend()
32
    {
33
        $data = new Attributes();
34
        $this->assertEmpty($data->getAttributes());
35
        $data->setAttribute('foo', 'bar');
36
        $data->setAttribute('ijn', 'ujm');
37
        $data->addAttributes([
38
            'ijn' => 'zgv',
39
            'edc' => 'rdx',
40
        ]);
41
        $this->assertEquals('zgv', $data->getAttribute('ijn'));
42
        $data->addAttributes([
43
            'ojv' => [
44
                'lkj',
45
                'nbv',
46
                'gfd',
47
            ],
48
        ]);
49
        $this->assertEquals('lkj;nbv;gfd', $data->getAttribute('ojv'));
50
51
        $data->setAttributes([]);
52
        $this->assertEmpty($data->getAttributes());
53
    }
54
55
    public function testStringInput()
56
    {
57
        $data = new Attributes();
58
        $this->assertEmpty($data->getAttributes());
59
        $data->addAttributes('avail="from:left;insecure:15em;"');
60
        $this->assertEquals('from:left;insecure:15em;', $data->getAttribute('avail'));
61
        $data->setAttribute('avail', 'xrb');
62
        $this->assertEquals('xrb', $data->getAttribute('avail'));
63
    }
64
65
    public function testRender()
66
    {
67
        $data = new Attributes();
68
        $this->assertEmpty($data->getAttributes());
69
        $data->addAttributes('avail="from:left;insecure:15em;"');
70
        $data->setAttribute('foo', 'bar');
71
        $data->setAttribute('ijn', 'ujm');
72
        $this->assertEquals(' avail="from:left;insecure:15em;" foo="bar" ijn="ujm"', $data->render());
73
    }
74
}
75
76
77
class Attributes
78
{
79
    use TAttributes;
80
81
    public function render(): string
82
    {
83
        return $this->renderAttributes();
84
    }
85
}
86