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
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Mezon\Conf\Conf; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* |
12
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
13
|
|
|
*/ |
14
|
|
|
class CustomHeaderActionsUnitTest extends ListBuilderTestsBase |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
* @see TestCase::setUp() |
21
|
|
|
* @psalm-suppress RedundantCondition |
22
|
|
|
*/ |
23
|
|
|
protected function setUp(): void |
24
|
|
|
{ |
25
|
|
|
Conf::setConfigStringValue('headers/layer', 'mock'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Testing data provider |
30
|
|
|
* |
31
|
|
|
* @return array testing data |
32
|
|
|
*/ |
33
|
|
|
public function actionsDataProvider(): array |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
// #0, the first case - simple header |
37
|
|
|
[ |
38
|
|
|
function (): object { |
39
|
|
|
// setup |
40
|
|
|
unset($_GET['create-button']); |
41
|
|
|
$listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords())); |
42
|
|
|
$listBuilder->setCustomHeaderActions('custom header actions'); |
43
|
|
|
return $listBuilder; |
44
|
|
|
}, |
45
|
|
|
function (string $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
|
|
|
// #1, the second case - full header |
54
|
|
|
[ |
55
|
|
|
function (): object { |
56
|
|
|
// setup |
57
|
|
|
$_GET['create-button'] = 1; |
58
|
|
|
$listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter($this->getRecords())); |
59
|
|
|
$listBuilder->setCustomHeaderActions('custom header actions'); |
60
|
|
|
return $listBuilder; |
61
|
|
|
}, |
62
|
|
|
function (string $result): void { |
63
|
|
|
// asserting method |
64
|
|
|
$this->assertStringContainsString('<form', $result); |
65
|
|
|
$this->assertStringContainsString('</form>', $result); |
66
|
|
|
$this->assertStringContainsString('method="post"', $result); |
67
|
|
|
$this->assertStringContainsString('custom header actions', $result); |
68
|
|
|
} |
69
|
|
|
], |
70
|
|
|
// #2, the third case - simple header |
71
|
|
|
[ |
72
|
|
|
function (): object { |
73
|
|
|
// setup |
74
|
|
|
$_GET['create-button'] = 1; |
75
|
|
|
$listBuilder = new ListBuilder\Common($this->getFields(), new FakeAdapter([])); |
76
|
|
|
$listBuilder->setCustomHeaderActions('custom header actions'); |
77
|
|
|
return $listBuilder; |
78
|
|
|
}, |
79
|
|
|
function (string $result): void { |
80
|
|
|
// asserting method |
81
|
|
|
$this->assertStringNotContainsString('<form', $result); |
82
|
|
|
$this->assertStringNotContainsString('</form>', $result); |
83
|
|
|
$this->assertStringNotContainsString('method="post"', $result); |
84
|
|
|
$this->assertStringNotContainsString('custom header actions', $result); |
85
|
|
|
} |
86
|
|
|
] |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Testing method |
92
|
|
|
* |
93
|
|
|
* @param callable $setup |
94
|
|
|
* setup method |
95
|
|
|
* @param callable $assertions |
96
|
|
|
* assertions method |
97
|
|
|
* @dataProvider actionsDataProvider |
98
|
|
|
*/ |
99
|
|
|
public function testCustomHeaderActions(callable $setup, callable $assertions): void |
100
|
|
|
{ |
101
|
|
|
// setup |
102
|
|
|
$obj = $setup(); |
103
|
|
|
|
104
|
|
|
// test body |
105
|
|
|
$result = $obj->listingForm(); |
106
|
|
|
|
107
|
|
|
// assertions |
108
|
|
|
$assertions($result); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|