|
1
|
|
|
<?php |
|
2
|
|
|
namespace Mezon\Gui\Tests\Common; |
|
3
|
|
|
|
|
4
|
|
|
use Mezon\Gui\ListBuilder; |
|
5
|
|
|
use Mezon\Gui\Tests\FakeAdapter; |
|
6
|
|
|
use Mezon\Gui\Tests\ListBuilderTestsBase; |
|
7
|
|
|
|
|
8
|
|
|
class ListBuilderCustomHeaderActionsUnitTest extends ListBuilderTestsBase |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Testing data provider |
|
13
|
|
|
* |
|
14
|
|
|
* @return array testing data |
|
15
|
|
|
*/ |
|
16
|
|
|
public function actionsDataProvider(): array |
|
17
|
|
|
{ |
|
18
|
|
|
return [ |
|
19
|
|
|
// #0, the first case - simple header |
|
20
|
|
|
[ |
|
21
|
|
|
function (): object { |
|
22
|
|
|
// setup |
|
23
|
|
|
unset($_GET['create-button']); |
|
24
|
|
|
$listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords())); |
|
25
|
|
|
$listBuilder->setCustomHeaderActions('custom header actions'); |
|
26
|
|
|
return $listBuilder; |
|
27
|
|
|
}, |
|
28
|
|
|
function ($result): void { |
|
29
|
|
|
// asserting method |
|
30
|
|
|
$this->assertStringContainsString('<form', $result); |
|
31
|
|
|
$this->assertStringContainsString('</form>', $result); |
|
32
|
|
|
$this->assertStringContainsString('method="post"', $result); |
|
33
|
|
|
$this->assertStringContainsString('custom header actions', $result); |
|
34
|
|
|
} |
|
35
|
|
|
], |
|
36
|
|
|
// #1, the second case - full header |
|
37
|
|
|
[ |
|
38
|
|
|
function (): object { |
|
39
|
|
|
// setup |
|
40
|
|
|
$_GET['create-button'] = 1; |
|
41
|
|
|
$listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords())); |
|
42
|
|
|
$listBuilder->setCustomHeaderActions('custom header actions'); |
|
43
|
|
|
return $listBuilder; |
|
44
|
|
|
}, |
|
45
|
|
|
function ($result): void { |
|
46
|
|
|
// asserting method |
|
47
|
|
|
$this->assertStringContainsString('<form', $result); |
|
48
|
|
|
$this->assertStringContainsString('</form>', $result); |
|
49
|
|
|
$this->assertStringContainsString('method="post"', $result); |
|
50
|
|
|
$this->assertStringContainsString('custom header actions', $result); |
|
51
|
|
|
} |
|
52
|
|
|
], |
|
53
|
|
|
// #2, the third case - simple header |
|
54
|
|
|
[ |
|
55
|
|
|
function (): object { |
|
56
|
|
|
// setup |
|
57
|
|
|
$_GET['create-button'] = 1; |
|
58
|
|
|
$listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter([])); |
|
59
|
|
|
$listBuilder->setCustomHeaderActions('custom header actions'); |
|
60
|
|
|
return $listBuilder; |
|
61
|
|
|
}, |
|
62
|
|
|
function ($result): void { |
|
63
|
|
|
// asserting method |
|
64
|
|
|
$this->assertStringNotContainsString('<form', $result); |
|
65
|
|
|
$this->assertStringNotContainsString('</form>', $result); |
|
66
|
|
|
$this->assertStringNotContainsString('method="post"', $result); |
|
67
|
|
|
$this->assertStringNotContainsString('custom header actions', $result); |
|
68
|
|
|
} |
|
69
|
|
|
] |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Testing method |
|
75
|
|
|
* |
|
76
|
|
|
* @param callable $setup |
|
77
|
|
|
* setup method |
|
78
|
|
|
* @param callable $assertions |
|
79
|
|
|
* assertions method |
|
80
|
|
|
* @dataProvider actionsDataProvider |
|
81
|
|
|
*/ |
|
82
|
|
|
public function testCustomHeaderActions(callable $setup, callable $assertions): void |
|
83
|
|
|
{ |
|
84
|
|
|
// setup |
|
85
|
|
|
$obj = $setup(); |
|
86
|
|
|
|
|
87
|
|
|
// test body |
|
88
|
|
|
$result = $obj->listingForm(); |
|
89
|
|
|
|
|
90
|
|
|
// assertions |
|
91
|
|
|
$assertions($result); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|