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

DateColumnTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 22
c 0
b 0
f 0
dl 0
loc 95
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 DateColumnTest extends CommonTestClass
13
{
14
    /**
15
     * @throws ConnectException
16
     */
17
    public function testDate(): void
18
    {
19
        $lib = new Columns\Date('add', 'Y-m-d', false);
20
        $this->assertEquals('2022-05-10', $lib->getValue($this->getRow()));
21
    }
22
23
    /**
24
     * @throws ConnectException
25
     */
26
    public function testDateStamp(): void
27
    {
28
        $lib = new Columns\Date('from');
29
        $this->assertEquals('2022-05-08', $lib->getValue($this->getRow()));
30
    }
31
32
    /**
33
     * @throws ConnectException
34
     */
35
    public function testDateEmpty(): void
36
    {
37
        $lib = new Columns\Date('to');
38
        $this->assertEmpty($lib->getValue($this->getRow()));
39
    }
40
41
    /**
42
     * @throws ConnectException
43
     */
44
    public function testTime(): void
45
    {
46
        $lib = new Columns\DateTime('add');
47
        $this->assertEquals('2022-05-10', $lib->getValue($this->getRow()));
48
    }
49
50
    /**
51
     * @throws ConnectException
52
     */
53
    public function testTimeStamp(): void
54
    {
55
        $lib = new Columns\DateTime('from', 'Y-m-d', true);
56
        $this->assertEquals('2022-05-08', $lib->getValue($this->getRow()));
57
    }
58
59
    /**
60
     * @throws ConnectException
61
     */
62
    public function testTimeEmpty(): void
63
    {
64
        $lib = new Columns\DateTime('to');
65
        $this->assertEmpty($lib->getValue($this->getRow()));
66
    }
67
68
    /**
69
     * @throws ConnectException
70
     */
71
    public function testDateDetail(): void
72
    {
73
        $lib = new Columns\DateDetail('from');
74
        $this->assertEquals('<span title="2022-05-08 08:53:20">2022-05-08</span>', $lib->getValue($this->getRow()));
75
    }
76
77
    /**
78
     * @throws ConnectException
79
     */
80
    public function testDateDetailEmpty(): void
81
    {
82
        $lib = new Columns\DateDetail('to');
83
        $this->assertEmpty($lib->getValue($this->getRow()));
84
    }
85
86
    /**
87
     * @throws ConnectException
88
     */
89
    public function testHours(): void
90
    {
91
        $lib = new Columns\HourMinute('min');
92
        $this->assertEquals('11:21', $lib->getValue($this->getRow()));
93
    }
94
95
    /**
96
     * @throws ConnectException
97
     */
98
    public function testHoursEmpty(): void
99
    {
100
        $lib = new Columns\HourMinute('to');
101
        $this->assertEquals('0:00', $lib->getValue($this->getRow()));
102
    }
103
104
    protected function getRow(): Row
105
    {
106
        return new Row(['id' => 4, 'name' => 'def', 'from' => 1652000000, 'to' => 0, 'add' => '2022-05-10 22:08', 'min' => 681, 'enabled' => 1]);
107
    }
108
}
109