1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Unit; |
5
|
|
|
|
6
|
|
|
use PerfectApp\Flash\FlashMessage; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
final class FlashMessageTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
private array $config = [ |
12
|
|
|
'primary' => [ |
13
|
|
|
'created' => 'Item created successfully' |
14
|
|
|
], |
15
|
|
|
'secondary' => [ |
16
|
|
|
'updated' => 'Item updated successfully' |
17
|
|
|
], |
18
|
|
|
'light' => [ |
19
|
|
|
'viewed' => 'Item viewed successfully' |
20
|
|
|
], |
21
|
|
|
'dark' => [ |
22
|
|
|
'deleted' => 'Item deleted successfully' |
23
|
|
|
], |
24
|
|
|
'success' => [ |
25
|
|
|
'saved' => 'Item saved successfully' |
26
|
|
|
], |
27
|
|
|
'info' => [ |
28
|
|
|
'found' => 'Item found successfully' |
29
|
|
|
], |
30
|
|
|
'warning' => [ |
31
|
|
|
'missing' => 'Item missing' |
32
|
|
|
], |
33
|
|
|
'danger' => [ |
34
|
|
|
'error' => 'An error occurred' |
35
|
|
|
] |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
public function testConstructor(): void |
39
|
|
|
{ |
40
|
|
|
$flashMessage = new FlashMessage($this->config); |
41
|
|
|
$this->assertInstanceOf(FlashMessage::class, $flashMessage); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testSetValidTypeAndAction(): void |
45
|
|
|
{ |
46
|
|
|
$flashMessage = new FlashMessage($this->config); |
47
|
|
|
$flashMessage->set('success', 'saved'); |
48
|
|
|
$this->expectOutputString('<div class="alert alert-success alert-dismissible fade show" role="alert"> <strong>Item saved successfully</strong> |
49
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'); |
50
|
|
|
$flashMessage->display(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testSetInvalidType(): void |
54
|
|
|
{ |
55
|
|
|
$flashMessage = new FlashMessage($this->config); |
56
|
|
|
$flashMessage->set('invalid', 'created'); |
57
|
|
|
$this->expectOutputString('<div class="alert alert-danger alert-dismissible fade show" role="alert"> <strong>ERROR: Invalid type "invalid" provided</strong> |
58
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'); |
59
|
|
|
$flashMessage->display(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testSetInvalidAction(): void |
63
|
|
|
{ |
64
|
|
|
$flashMessage = new FlashMessage($this->config); |
65
|
|
|
$flashMessage->set('primary', 'invalid'); |
66
|
|
|
$this->expectOutputString('<div class="alert alert-danger alert-dismissible fade show" role="alert"> <strong>ERROR: Invalid action "invalid" provided</strong> |
67
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'); |
68
|
|
|
$flashMessage->display(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testSetInvalidTypeAndAction(): void |
72
|
|
|
{ |
73
|
|
|
$flashMessage = new FlashMessage($this->config); |
74
|
|
|
$flashMessage->set('invalid', 'invalid'); |
75
|
|
|
$this->expectOutputString('<div class="alert alert-danger alert-dismissible fade show" role="alert"> <strong>ERROR: Invalid type "invalid" provided</strong> |
76
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'); |
77
|
|
|
$flashMessage->display(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|