1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace cliTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_address_handler\Handler; |
8
|
|
|
use kalanis\kw_address_handler\Sources\Sources; |
9
|
|
|
use kalanis\kw_connect\arrays\Connector; |
10
|
|
|
use kalanis\kw_connect\core\ConnectException; |
11
|
|
|
use kalanis\kw_connect\core\Interfaces\IOrder; |
12
|
|
|
use kalanis\kw_pager\BasicPager; |
13
|
|
|
use kalanis\kw_paging\Positions; |
14
|
|
|
use kalanis\kw_paging\Render\CliPager; |
15
|
|
|
use kalanis\kw_table\core\Connector\ArrayFilterForm; |
16
|
|
|
use kalanis\kw_table\core\Table; |
17
|
|
|
use kalanis\kw_table\core\Table\Columns; |
18
|
|
|
use kalanis\kw_table\core\Table\Order; |
19
|
|
|
use kalanis\kw_table\core\TableException; |
20
|
|
|
use kalanis\kw_table\form_kw\Fields\TextContains; |
21
|
|
|
use kalanis\kw_table\output_cli\CliRenderer; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
class RenderTest extends CommonTestClass |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @throws ConnectException |
28
|
|
|
* @throws TableException |
29
|
|
|
*/ |
30
|
|
|
public function testBasics(): void |
31
|
|
|
{ |
32
|
|
|
$lib = new Table(); |
33
|
|
|
$render = new CliRenderer($lib); |
34
|
|
|
$lib->setOutput($render); |
35
|
|
|
|
36
|
|
|
$lib->addColumn('id', new Columns\Basic('id')); |
37
|
|
|
$lib->addColumn('name', new Columns\Basic('name')); |
38
|
|
|
$lib->addColumn('title', new Columns\Basic('desc')); |
39
|
|
|
|
40
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
41
|
|
|
|
42
|
|
|
$this->assertEquals( |
43
|
|
|
'| --- | ----- | ------ |' . PHP_EOL |
44
|
|
|
. '| :id | :name | :title |' . PHP_EOL |
45
|
|
|
. '| --- | ----- | ------ |' . PHP_EOL |
46
|
|
|
. '| 1 | abc | fill |' . PHP_EOL |
47
|
|
|
. '| 2 | def | dude |' . PHP_EOL |
48
|
|
|
. '| 3 | ghi | know |' . PHP_EOL |
49
|
|
|
. '| 4 | jkl | hate |' . PHP_EOL |
50
|
|
|
. '| 5 | mno | call |' . PHP_EOL |
51
|
|
|
. '| 6 | pqr | that |' . PHP_EOL |
52
|
|
|
. '| 7 | stu | life |' . PHP_EOL |
53
|
|
|
. '| 8 | vwx | felt |' . PHP_EOL |
54
|
|
|
. '| 9 | yz- | love |' . PHP_EOL |
55
|
|
|
. '| --- | ----- | ------ |' . PHP_EOL |
56
|
|
|
, $lib->render()); |
57
|
|
|
|
58
|
|
|
$this->assertNotEmpty($render->getTableEngine()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @throws ConnectException |
63
|
|
|
* @throws TableException |
64
|
|
|
*/ |
65
|
|
|
public function testOrderedFromPreset(): void |
66
|
|
|
{ |
67
|
|
|
$lib = new Table(); |
68
|
|
|
$lib->setOutput(new CliRenderer($lib)); |
69
|
|
|
|
70
|
|
|
$src = new Sources(); |
71
|
|
|
$src->setAddress('//foo/bar'); |
72
|
|
|
$lib->addOrder(new Order(new Handler($src))); |
73
|
|
|
|
74
|
|
|
$lib->addOrderedColumn('id', new Columns\Basic('id')); |
75
|
|
|
$lib->addOrderedColumn('name', new Columns\Basic('name')); |
76
|
|
|
$lib->addColumn('title', new Columns\Basic('desc')); |
77
|
|
|
|
78
|
|
|
$lib->addOrdering('id', IOrder::ORDER_DESC); |
79
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
80
|
|
|
|
81
|
|
|
$this->assertEquals( |
82
|
|
|
'| ----- | ------ | ------ |' . PHP_EOL |
83
|
|
|
. '| *^:id | v:name | :title |' . PHP_EOL |
84
|
|
|
. '| ----- | ------ | ------ |' . PHP_EOL |
85
|
|
|
. '| 9 | yz- | love |' . PHP_EOL |
86
|
|
|
. '| 8 | vwx | felt |' . PHP_EOL |
87
|
|
|
. '| 7 | stu | life |' . PHP_EOL |
88
|
|
|
. '| 6 | pqr | that |' . PHP_EOL |
89
|
|
|
. '| 5 | mno | call |' . PHP_EOL |
90
|
|
|
. '| 4 | jkl | hate |' . PHP_EOL |
91
|
|
|
. '| 3 | ghi | know |' . PHP_EOL |
92
|
|
|
. '| 2 | def | dude |' . PHP_EOL |
93
|
|
|
. '| 1 | abc | fill |' . PHP_EOL |
94
|
|
|
. '| ----- | ------ | ------ |' . PHP_EOL |
95
|
|
|
, $lib->render()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @throws ConnectException |
100
|
|
|
* @throws TableException |
101
|
|
|
*/ |
102
|
|
|
public function testOrderedFromLink1(): void |
103
|
|
|
{ |
104
|
|
|
$lib = new Table(); |
105
|
|
|
$lib->setOutput(new CliRenderer($lib)); |
106
|
|
|
|
107
|
|
|
$src = new Sources(); |
108
|
|
|
$src->setAddress('//foo/bar?column=name&direction=ASC'); |
109
|
|
|
$lib->addOrder(new Order(new Handler($src))); |
110
|
|
|
|
111
|
|
|
$lib->addOrderedColumn('id', new Columns\Basic('id')); |
112
|
|
|
$lib->addOrderedColumn('name', new Columns\Basic('name')); |
113
|
|
|
$lib->addColumn('title', new Columns\Basic('desc')); |
114
|
|
|
|
115
|
|
|
$lib->addOrdering('id', IOrder::ORDER_DESC); |
116
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
117
|
|
|
|
118
|
|
|
$this->assertEquals( |
119
|
|
|
'| ---- | ------- | ------ |' . PHP_EOL |
120
|
|
|
. '| v:id | *v:name | :title |' . PHP_EOL |
121
|
|
|
. '| ---- | ------- | ------ |' . PHP_EOL |
122
|
|
|
. '| 1 | abc | fill |' . PHP_EOL |
123
|
|
|
. '| 2 | def | dude |' . PHP_EOL |
124
|
|
|
. '| 3 | ghi | know |' . PHP_EOL |
125
|
|
|
. '| 4 | jkl | hate |' . PHP_EOL |
126
|
|
|
. '| 5 | mno | call |' . PHP_EOL |
127
|
|
|
. '| 6 | pqr | that |' . PHP_EOL |
128
|
|
|
. '| 7 | stu | life |' . PHP_EOL |
129
|
|
|
. '| 8 | vwx | felt |' . PHP_EOL |
130
|
|
|
. '| 9 | yz- | love |' . PHP_EOL |
131
|
|
|
. '| ---- | ------- | ------ |' . PHP_EOL |
132
|
|
|
, $lib->render()); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @throws ConnectException |
137
|
|
|
* @throws TableException |
138
|
|
|
*/ |
139
|
|
|
public function testOrderedFromLink2(): void |
140
|
|
|
{ |
141
|
|
|
$lib = new Table(); |
142
|
|
|
$lib->setOutput(new CliRenderer($lib)); |
143
|
|
|
|
144
|
|
|
$src = new Sources(); |
145
|
|
|
$src->setAddress('//foo/bar?column=name&direction=DESC'); |
146
|
|
|
$lib->addOrder(new Order(new Handler($src))); |
147
|
|
|
|
148
|
|
|
$lib->addOrderedColumn('id', new Columns\Basic('id')); |
149
|
|
|
$lib->addOrderedColumn('name', new Columns\Basic('name')); |
150
|
|
|
$lib->addColumn('title', new Columns\Basic('desc')); |
151
|
|
|
|
152
|
|
|
$lib->addOrdering('id', IOrder::ORDER_DESC); |
153
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
154
|
|
|
|
155
|
|
|
$this->assertEquals( |
156
|
|
|
'| ---- | ------- | ------ |' . PHP_EOL |
157
|
|
|
. '| v:id | *^:name | :title |' . PHP_EOL |
158
|
|
|
. '| ---- | ------- | ------ |' . PHP_EOL |
159
|
|
|
. '| 9 | yz- | love |' . PHP_EOL |
160
|
|
|
. '| 8 | vwx | felt |' . PHP_EOL |
161
|
|
|
. '| 7 | stu | life |' . PHP_EOL |
162
|
|
|
. '| 6 | pqr | that |' . PHP_EOL |
163
|
|
|
. '| 5 | mno | call |' . PHP_EOL |
164
|
|
|
. '| 4 | jkl | hate |' . PHP_EOL |
165
|
|
|
. '| 3 | ghi | know |' . PHP_EOL |
166
|
|
|
. '| 2 | def | dude |' . PHP_EOL |
167
|
|
|
. '| 1 | abc | fill |' . PHP_EOL |
168
|
|
|
. '| ---- | ------- | ------ |' . PHP_EOL |
169
|
|
|
, $lib->render()); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @throws ConnectException |
174
|
|
|
* @throws TableException |
175
|
|
|
*/ |
176
|
|
|
public function testFilter(): void |
177
|
|
|
{ |
178
|
|
|
$lib = new Table(); |
179
|
|
|
$lib->setOutput(new CliRenderer($lib)); |
180
|
|
|
$lib->addHeaderFilter(new ArrayFilterForm([ |
181
|
|
|
'desc' => 'e', |
182
|
|
|
])); |
183
|
|
|
|
184
|
|
|
$src = new Sources(); |
185
|
|
|
$src->setAddress('//foo/bar'); |
186
|
|
|
$lib->addOrder(new Order(new Handler($src))); |
187
|
|
|
|
188
|
|
|
$lib->addColumn('id', new Columns\Basic('id')); |
189
|
|
|
$lib->addColumn('name', new Columns\Basic('name'), new TextContains()); |
190
|
|
|
$lib->addColumn('title', new Columns\Basic('desc'), new TextContains()); |
191
|
|
|
|
192
|
|
|
$lib->addOrdering('id', IOrder::ORDER_DESC); |
193
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
194
|
|
|
|
195
|
|
|
$this->assertEquals( |
196
|
|
|
'| --- | ------ | ------- |' . PHP_EOL |
197
|
|
|
. '| :id | >:name | >:title |' . PHP_EOL |
198
|
|
|
. '| --- | ------ | ------- |' . PHP_EOL |
199
|
|
|
. '| 9 | yz- | love |' . PHP_EOL |
200
|
|
|
. '| 8 | vwx | felt |' . PHP_EOL |
201
|
|
|
. '| 7 | stu | life |' . PHP_EOL |
202
|
|
|
. '| 4 | jkl | hate |' . PHP_EOL |
203
|
|
|
. '| 2 | def | dude |' . PHP_EOL |
204
|
|
|
. '| --- | ------ | ------- |' . PHP_EOL |
205
|
|
|
, $lib->render()); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @throws ConnectException |
210
|
|
|
* @throws TableException |
211
|
|
|
*/ |
212
|
|
|
public function testPager1(): void |
213
|
|
|
{ |
214
|
|
|
$lib = new Table(); |
215
|
|
|
$lib->setOutput(new CliRenderer($lib)); |
216
|
|
|
|
217
|
|
|
// pager |
218
|
|
|
$pager = new BasicPager(); |
219
|
|
|
$pager->setLimit(3); |
220
|
|
|
$pager->setActualPage(1); |
221
|
|
|
$lib->addPager(new CliPager(new Positions($pager))); |
222
|
|
|
|
223
|
|
|
$lib->addColumn('id', new Columns\Basic('id')); |
224
|
|
|
$lib->addColumn('name', new Columns\Basic('name')); |
225
|
|
|
$lib->addColumn('title', new Columns\Basic('desc')); |
226
|
|
|
|
227
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
228
|
|
|
|
229
|
|
|
$this->assertEquals( |
230
|
|
|
'| --- | ----- | ------ |' . PHP_EOL |
231
|
|
|
. '| :id | :name | :title |' . PHP_EOL |
232
|
|
|
. '| --- | ----- | ------ |' . PHP_EOL |
233
|
|
|
. '| 1 | abc | fill |' . PHP_EOL |
234
|
|
|
. '| 2 | def | dude |' . PHP_EOL |
235
|
|
|
. '| 3 | ghi | know |' . PHP_EOL |
236
|
|
|
. '| --- | ----- | ------ |' . PHP_EOL |
237
|
|
|
. '' . PHP_EOL |
238
|
|
|
. '-- | - | 1 | 2 > | 3 >>' . PHP_EOL |
239
|
|
|
. 'Showing results 1 - 3 of total 9' . PHP_EOL |
240
|
|
|
, $lib->render()); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @throws ConnectException |
245
|
|
|
* @throws TableException |
246
|
|
|
*/ |
247
|
|
|
public function testPager2(): void |
248
|
|
|
{ |
249
|
|
|
$lib = new Table(); |
250
|
|
|
$lib->setOutput(new CliRenderer($lib)); |
251
|
|
|
|
252
|
|
|
// pager |
253
|
|
|
$pager = new BasicPager(); |
254
|
|
|
$pager->setLimit(3); |
255
|
|
|
$pager->setActualPage(2); |
256
|
|
|
$lib->addPager(new CliPager(new Positions($pager))); |
257
|
|
|
|
258
|
|
|
$lib->addColumn('id', new Columns\Basic('id')); |
259
|
|
|
$lib->addColumn('name', new Columns\Basic('name')); |
260
|
|
|
$lib->addColumn('title', new Columns\Basic('desc')); |
261
|
|
|
|
262
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
263
|
|
|
|
264
|
|
|
$this->assertEquals( |
265
|
|
|
'| --- | ----- | ------ |' . PHP_EOL |
266
|
|
|
. '| :id | :name | :title |' . PHP_EOL |
267
|
|
|
. '| --- | ----- | ------ |' . PHP_EOL |
268
|
|
|
. '| 4 | jkl | hate |' . PHP_EOL |
269
|
|
|
. '| 5 | mno | call |' . PHP_EOL |
270
|
|
|
. '| 6 | pqr | that |' . PHP_EOL |
271
|
|
|
. '| --- | ----- | ------ |' . PHP_EOL |
272
|
|
|
. '' . PHP_EOL |
273
|
|
|
. '<< 1 | < 1 | 2 | 3 > | 3 >>' . PHP_EOL |
274
|
|
|
. 'Showing results 4 - 6 of total 9' . PHP_EOL |
275
|
|
|
, $lib->render()); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @throws ConnectException |
280
|
|
|
* @throws TableException |
281
|
|
|
*/ |
282
|
|
|
public function testPager3(): void |
283
|
|
|
{ |
284
|
|
|
$lib = new Table(); |
285
|
|
|
$lib->setOutput(new CliRenderer($lib)); |
286
|
|
|
|
287
|
|
|
// pager |
288
|
|
|
$pager = new BasicPager(); |
289
|
|
|
$pager->setLimit(3); |
290
|
|
|
$pager->setActualPage(3); |
291
|
|
|
$lib->addPager(new CliPager(new Positions($pager))); |
292
|
|
|
|
293
|
|
|
$lib->addColumn('id', new Columns\Basic('id')); |
294
|
|
|
$lib->addColumn('name', new Columns\Basic('name')); |
295
|
|
|
$lib->addColumn('title', new Columns\Basic('desc')); |
296
|
|
|
|
297
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
298
|
|
|
|
299
|
|
|
$this->assertEquals( |
300
|
|
|
'| --- | ----- | ------ |' . PHP_EOL |
301
|
|
|
. '| :id | :name | :title |' . PHP_EOL |
302
|
|
|
. '| --- | ----- | ------ |' . PHP_EOL |
303
|
|
|
. '| 7 | stu | life |' . PHP_EOL |
304
|
|
|
. '| 8 | vwx | felt |' . PHP_EOL |
305
|
|
|
. '| 9 | yz- | love |' . PHP_EOL |
306
|
|
|
. '| --- | ----- | ------ |' . PHP_EOL |
307
|
|
|
. '' . PHP_EOL |
308
|
|
|
. '<< 1 | < 2 | 3 | - | --' . PHP_EOL |
309
|
|
|
. 'Showing results 7 - 9 of total 9' . PHP_EOL |
310
|
|
|
, $lib->render()); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @throws ConnectException |
315
|
|
|
* @throws TableException |
316
|
|
|
*/ |
317
|
|
|
public function testEverything(): void |
318
|
|
|
{ |
319
|
|
|
$lib = new Table(); |
320
|
|
|
$lib->setOutput(new CliRenderer($lib)); |
321
|
|
|
|
322
|
|
|
// filter |
323
|
|
|
$lib->addHeaderFilter(new ArrayFilterForm([ |
324
|
|
|
'desc' => 'e', |
325
|
|
|
])); |
326
|
|
|
|
327
|
|
|
// order |
328
|
|
|
$src = new Sources(); |
329
|
|
|
$src->setAddress('//foo/bar'); |
330
|
|
|
$lib->addOrder(new Order(new Handler($src))); |
331
|
|
|
|
332
|
|
|
// pager |
333
|
|
|
$pager = new BasicPager(); |
334
|
|
|
$pager->setLimit(3); |
335
|
|
|
$pager->setActualPage(2); |
336
|
|
|
$lib->addPager(new CliPager(new Positions($pager))); |
337
|
|
|
|
338
|
|
|
$lib->addOrderedColumn('id', new Columns\Basic('id')); |
339
|
|
|
$lib->addOrderedColumn('name', new Columns\Basic('name'), new TextContains()); |
340
|
|
|
$lib->addColumn('title', new Columns\Basic('desc'), new TextContains()); |
341
|
|
|
|
342
|
|
|
$lib->addDataSetConnector(new Connector($this->basicData())); |
343
|
|
|
|
344
|
|
|
$this->assertEquals( |
345
|
|
|
'| ----- | ------- | ------- |' . PHP_EOL |
346
|
|
|
. '| *v:id | v>:name | >:title |' . PHP_EOL |
347
|
|
|
. '| ----- | ------- | ------- |' . PHP_EOL |
348
|
|
|
. '| 8 | vwx | felt |' . PHP_EOL |
349
|
|
|
. '| 9 | yz- | love |' . PHP_EOL |
350
|
|
|
. '| ----- | ------- | ------- |' . PHP_EOL |
351
|
|
|
. '' . PHP_EOL |
352
|
|
|
. '<< 1 | < 1 | 2 | - | --' . PHP_EOL |
353
|
|
|
. 'Showing results 4 - 5 of total 5' . PHP_EOL |
354
|
|
|
, $lib->render()); |
355
|
|
|
} |
356
|
|
|
} |
357
|
|
|
|