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
|
|
|
/** |
9
|
|
|
* |
10
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
11
|
|
|
*/ |
12
|
|
|
class NoItemsCreateButtonUnitTest extends ListBuilderTestsBase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Testing data provider |
17
|
|
|
* |
18
|
|
|
* @return array testing data |
19
|
|
|
*/ |
20
|
|
|
public function actionsDataProvider(): array |
21
|
|
|
{ |
22
|
|
|
return [ |
23
|
|
|
// #0, the first case - empty listing |
24
|
|
|
[ |
25
|
|
|
function (): object { |
26
|
|
|
// setup |
27
|
|
|
unset($_GET['create-button']); |
28
|
|
|
return new ListBuilder\Common($this->getFields(), new FakeAdapter([])); |
29
|
|
|
}, |
30
|
|
|
function (string $result): void { |
31
|
|
|
// asserting method |
32
|
|
|
$this->assertStringNotContainsString('create-button"', $result); |
33
|
|
|
} |
34
|
|
|
], |
35
|
|
|
// #1, the second case - full header |
36
|
|
|
[ |
37
|
|
|
function (): object { |
38
|
|
|
// setup |
39
|
|
|
$_GET['create-button'] = 1; |
40
|
|
|
if(isset($_GET['create-page-endpoint'])){ |
41
|
|
|
unset($_GET['create-page-endpoint']); |
42
|
|
|
} |
43
|
|
|
return new ListBuilder\Common($this->getFields(), new FakeAdapter([])); |
44
|
|
|
}, |
45
|
|
|
function (string $result): void { |
46
|
|
|
// asserting method |
47
|
|
|
$this->assertStringContainsString('../create/', $result); |
48
|
|
|
} |
49
|
|
|
], |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Testing create button absence |
55
|
|
|
* |
56
|
|
|
* * @dataProvider actionsDataProvider |
57
|
|
|
*/ |
58
|
|
|
public function testCreateButtonAbsenceForEmptyList(callable $setup, callable $assertions): void |
59
|
|
|
{ |
60
|
|
|
// setup |
61
|
|
|
$obj = $setup(); |
62
|
|
|
|
63
|
|
|
// test body |
64
|
|
|
$result = $obj->listingForm(); |
65
|
|
|
|
66
|
|
|
// assertions |
67
|
|
|
$assertions($result); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|