Passed
Push — master ( 62264f...226050 )
by Petr
08:16
created

XWrapper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace coreTests\Columns;
4
5
6
use CommonTestClass;
7
use kalanis\kw_connect\arrays\Row;
8
use kalanis\kw_connect\core\ConnectException;
9
use kalanis\kw_table\core\Table\Columns;
10
11
12
class SimpleColumnTest extends CommonTestClass
13
{
14
    /**
15
     * @throws ConnectException
16
     */
17
    public function testCore(): void
18
    {
19
        $lib = new XColumn('name');
20
        $this->assertEquals('name', $lib->getSourceName());
21
        $this->assertEquals('name', $lib->getFilterName());
22
        $this->assertEquals('', $lib->getHeaderText());
23
        $lib->setHeaderText(null);
24
        $this->assertEquals('name', $lib->getHeaderText());
25
        $lib->setHeaderText('else');
26
        $this->assertEquals('else', $lib->getHeaderText());
27
        $this->assertTrue($lib->canOrder());
28
29
        $data = $this->getRow();
30
        $this->assertEquals('def', $lib->getValue($data));
31
        $this->assertEquals(456, $lib->getOverrideValue($data, 'size'));
32
33
        $this->assertEquals('def', $lib->translate($data));
34
35
        $this->assertFalse($lib->hasHeaderFilterField());
36
        $this->assertFalse($lib->hasFooterFilterField());
37
        $this->assertEmpty($lib->getHeaderFilterField());
38
        $this->assertEmpty($lib->getFooterFilterField());
39
        $lib->setHeaderFiltering(new \XField());
40
        $lib->setFooterFiltering(new \XField());
41
        $this->assertTrue($lib->hasHeaderFilterField());
42
        $this->assertTrue($lib->hasFooterFilterField());
43
    }
44
45
    public function testWrapper(): void
46
    {
47
        $lib = new XWrapper();
48
        $lib->addWrapper('li', ['baz' => 'uiy']);
49
        $this->assertEquals('<li baz="uiy">def</li>', $lib->formattedData('def'));
50
        $lib->addWrapper('ul', 'foo="bar"');
51
        $this->assertEquals('<ul foo="bar"><li baz="uiy">def</li></ul>', $lib->formattedData('def'));
52
    }
53
54
    /**
55
     * @throws ConnectException
56
     */
57
    public function testBasicWithConvert(): void
58
    {
59
        $lib = new Columns\Basic('desc');
60
        $data = $this->getRow();
61
        $this->assertEquals('<lang_to_"convert">', $lib->getValue($data));
62
        $lib->setEscapeFlags(ENT_IGNORE);
63
        $this->assertEquals('&lt;lang_to_"convert"&gt;', $lib->getValue($data));
64
    }
65
66
    /**
67
     * @throws ConnectException
68
     */
69
    public function testStaticBasic(): void
70
    {
71
        $lib = new Columns\CStatic('to out', '', 'id');
72
        $this->assertEquals('to out', $lib->getValue($this->getRow()));
73
    }
74
75
    /**
76
     * @throws ConnectException
77
     */
78
    public function testStaticStyle(): void
79
    {
80
        $lib = new Columns\CStatic('to out', 'style_me', 'id');
81
        $this->assertEquals('<span class="style_me">to out</span>', $lib->getValue($this->getRow()));
82
    }
83
84
    /**
85
     * @throws ConnectException
86
     */
87
    public function testBold(): void
88
    {
89
        $lib = new Columns\Bold('name');
90
        $this->assertEquals('<strong>def</strong>', $lib->getValue($this->getRow()));
91
    }
92
93
    /**
94
     * @throws ConnectException
95
     */
96
    public function testEmpty(): void
97
    {
98
        $lib = new Columns\CEmpty();
99
        $this->assertEmpty($lib->getValue($this->getRow()));
100
        $this->assertFalse($lib->canOrder());
101
    }
102
103
    /**
104
     * @throws ConnectException
105
     */
106
    public function testCurrency(): void
107
    {
108
        $lib = new Columns\Currency('size', 'EUR');
109
        $this->assertEquals('456 EUR', $lib->getValue($this->getRow()));
110
    }
111
112
    /**
113
     * @throws ConnectException
114
     */
115
    public function testEmail(): void
116
    {
117
        $lib = new Columns\Email('name');
118
        $this->assertEquals('<a href="mailto:def">def</a>', $lib->getValue($this->getRow()));
119
    }
120
121
    /**
122
     * @throws ConnectException
123
     */
124
    public function testPreformatted(): void
125
    {
126
        $lib = new Columns\Pre('desc');
127
        $this->assertEquals('<lang_to_"convert">', $lib->getValue($this->getRow()));
128
    }
129
130
    /**
131
     * @throws ConnectException
132
     */
133
    public function testFormat(): void
134
    {
135
        $lib = new Columns\Sprintf('name', '>> %s <<');
136
        $this->assertEquals('>> def <<', $lib->getValue($this->getRow()));
137
    }
138
139
    protected function getRow(): Row
140
    {
141
        return new Row(['id' => 2, 'name' => 'def', 'desc' => '<lang_to_"convert">', 'size' => 456, 'enabled' => 0]);
142
    }
143
}
144
145
146
class XColumn extends Columns\AColumn
147
{
148
    public function __construct($sourceName)
149
    {
150
        $this->sourceName = $sourceName;
151
    }
152
}
153
154
155
class XWrapper
156
{
157
    use Columns\TWrappers;
158
159
    public function formattedData($data): string
160
    {
161
        return $this->formatData($data);
162
    }
163
}
164