Repository navigation
Expand file tree
/
Copy pathTableTest.php
More file actions
156 lines (147 loc) · 3.87 KB
/
Copy pathTableTest.php
File metadata and controls
156 lines (147 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
declare(strict_types=1);
namespace PHPForge\Debug\Tests\Helper;
use PHPForge\Debug\Helper\Table;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use UIAwesome\Html\Table\{Td, Tr};
/**
* Unit tests for {@see Table} covering the header row, the header-less variant, and the custom shell classes.
*/
#[Group('helpers')]
#[Group('table')]
final class TableTest extends TestCase
{
public function testBuildFallsBackToTheSharedTableClass(): void
{
self::assertSame(
<<<HTML
<table class="yii-debug-table">
<tbody>
</tbody>
</table>
HTML,
Table::build([], [])->render(),
'Default class must be the shared debugger table class.',
);
}
public function testBuildKeepsTheSharedShellDecorableByTheCaller(): void
{
self::assertSame(
<<<HTML
<table class="yii-debug-table yii-debug-table-mono" style='table-layout: fixed;'>
<thead>
<tr>
<th scope="col">
Name
</th>
</tr>
</thead><tbody>
<tr>
<td>
1
</td><td>
home
</td>
</tr>
</tbody>
</table>
HTML,
Table::build(['Name'], self::rows(), 'yii-debug-table yii-debug-table-mono')
->style(['table-layout' => 'fixed'])
->render(),
'Decorations must survive on the returned element.',
);
}
public function testRenderAcceptsCustomShellClasses(): void
{
self::assertSame(
<<<HTML
<div class="yii-debug-table-wrap yii-debug-route-trace-wrap">
<table class="yii-debug-table yii-debug-route-trace">
<thead>
<tr>
<th scope="col">
#
</th>
</tr>
</thead><tbody>
</tbody>
</table>
</div>
HTML,
Table::render(
['#'],
[],
'yii-debug-table yii-debug-route-trace',
'yii-debug-table-wrap yii-debug-route-trace-wrap',
),
'Both shell classes must reach the wrapper and the table.',
);
}
public function testRenderOmitsTheHeaderRowWithoutLabels(): void
{
self::assertSame(
<<<HTML
<div class="yii-debug-table-wrap">
<table class="yii-debug-table">
<tbody>
<tr>
<td>
1
</td><td>
home
</td>
</tr>
</tbody>
</table>
</div>
HTML,
Table::render([], self::rows()),
'An empty label list must skip the `thead` entirely.',
);
}
public function testRenderWrapsTheHeaderAndBodyRows(): void
{
self::assertSame(
<<<HTML
<div class="yii-debug-table-wrap">
<table class="yii-debug-table">
<thead>
<tr>
<th scope="col">
#
</th><th scope="col">
Route
</th>
</tr>
</thead><tbody>
<tr>
<td>
1
</td><td>
home
</td>
</tr>
</tbody>
</table>
</div>
HTML,
Table::render(['#', 'Route'], self::rows()),
'Column labels must render as scoped header cells.',
);
}
/**
* @return list<Tr>
*/
private static function rows(): array
{
return [
Tr::tag()
->html(
Td::tag()->content('1'),
Td::tag()->content('home'),
),
];
}
}