1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Boduch\Grid\Grid; |
4
|
|
|
|
5
|
|
|
class GridTest extends GridBuilderTestCase |
6
|
|
|
{ |
7
|
|
|
public function testAddColumn() |
8
|
|
|
{ |
9
|
|
|
$grid = new Grid($this->gridHelper); |
10
|
|
|
$grid->addColumn('name', [ |
11
|
|
|
'title' => 'First name' |
12
|
|
|
]); |
13
|
|
|
$grid->addColumn('sex', [ |
14
|
|
|
'title' => 'Sex', |
15
|
|
|
'sortable' => true |
16
|
|
|
]); |
17
|
|
|
|
18
|
|
|
$this->assertInstanceOf(\Boduch\Grid\Column::class, $grid->getColumns()['name']); |
19
|
|
|
$this->assertEquals('First name', $grid->getColumns()['name']->getTitle()); |
20
|
|
|
|
21
|
|
|
$this->assertInstanceOf(\Boduch\Grid\Column::class, $grid->getColumns()['sex']); |
22
|
|
|
$this->assertEquals('Sex', $grid->getColumns()['sex']->getTitle()); |
23
|
|
|
$this->assertTrue($grid->getColumns()['sex']->isSortable()); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testAddColumnWithDecorators() |
27
|
|
|
{ |
28
|
|
|
$grid = new Grid($this->gridHelper); |
29
|
|
|
$grid->addColumn('name', [ |
30
|
|
|
'title' => 'First name', |
31
|
|
|
'clickable' => function () { |
32
|
|
|
return ''; |
33
|
|
|
}, |
34
|
|
|
'decorators' => [ |
35
|
|
|
new \Boduch\Grid\Decorators\Url() |
36
|
|
|
] |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$column = $grid->getColumns()['name']; |
40
|
|
|
|
41
|
|
|
$this->assertEquals(2, count($column->getDecorators())); |
42
|
|
|
$this->assertInstanceOf(\Boduch\Grid\Decorators\DecoratorInterface::class, $column->getDecorators()[0]); |
43
|
|
|
$this->assertInstanceOf(\Boduch\Grid\Decorators\DecoratorInterface::class, $column->getDecorators()[1]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testRenderColumnWithDecorator() |
47
|
|
|
{ |
48
|
|
|
$grid = new Grid($this->gridHelper); |
49
|
|
|
$grid->addColumn('website', [ |
50
|
|
|
'title' => 'Website', |
51
|
|
|
'decorators' => [ |
52
|
|
|
new \Boduch\Grid\Decorators\Url() |
53
|
|
|
] |
54
|
|
|
]); |
55
|
|
|
$grid->addColumn('id', [ |
56
|
|
|
'title' => 'ID', |
57
|
|
|
'clickable' => function ($row) { |
58
|
|
|
return '<a href="http://4programmers.net">' . $row['id'] . '</a>'; |
59
|
|
|
} |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
$collection = collect([ |
63
|
|
|
['id' => 1, 'website' => 'http://4programmers.net'] |
64
|
|
|
]); |
65
|
|
|
|
66
|
|
|
$source = new \Boduch\Grid\Source\CollectionSource($collection); |
67
|
|
|
$grid->setSource($source); |
68
|
|
|
|
69
|
|
|
$rows = $grid->getRows(); |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf(\Boduch\Grid\Rows::class, $rows); |
72
|
|
|
$this->assertInstanceOf(\Boduch\Grid\Row::class, $rows[0]); |
73
|
|
|
|
74
|
|
|
$this->assertEquals("<a href=\"http://4programmers.net\">\nhttp://4programmers.net\n</a>\n", (string) $rows[0]->getValue('website')); |
75
|
|
|
$this->assertEquals("<a href=\"http://4programmers.net\">1</a>", (string) $rows[0]->getValue('id')); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|