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