|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\PropellerAdmin\Events\Listeners; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Events\NavigationReady; |
|
8
|
|
|
use AbterPhp\Framework\Navigation\Navigation; |
|
9
|
|
|
use AbterPhp\PropellerAdmin\Decorator\General as GeneralDecorator; |
|
10
|
|
|
use AbterPhp\PropellerAdmin\Decorator\Navigation\Navbar as NavbarDecorator; |
|
11
|
|
|
use AbterPhp\PropellerAdmin\Decorator\Navigation\Primary as PrimaryDecorator; |
|
12
|
|
|
use AbterPhp\PropellerAdmin\Events\Listeners\NavigationBuilder as Listener; |
|
13
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
class NavigationBuilderTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var Listener - System Under Test */ |
|
19
|
|
|
protected $sut; |
|
20
|
|
|
|
|
21
|
|
|
/** @var PrimaryDecorator|MockObject */ |
|
22
|
|
|
protected $primaryDecoratorMock; |
|
23
|
|
|
|
|
24
|
|
|
/** @var NavbarDecorator|MockObject */ |
|
25
|
|
|
protected $navbarDecoratorMock; |
|
26
|
|
|
|
|
27
|
|
|
/** @var GeneralDecorator|MockObject */ |
|
28
|
|
|
protected $generalDecoratorMock; |
|
29
|
|
|
|
|
30
|
|
|
public function setUp(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->primaryDecoratorMock = $this->getMockBuilder(PrimaryDecorator::class) |
|
33
|
|
|
->disableOriginalConstructor() |
|
34
|
|
|
->onlyMethods(['init', 'decorate']) |
|
35
|
|
|
->getMock(); |
|
36
|
|
|
|
|
37
|
|
|
$this->navbarDecoratorMock = $this->getMockBuilder(NavbarDecorator::class) |
|
38
|
|
|
->disableOriginalConstructor() |
|
39
|
|
|
->onlyMethods(['init', 'decorate']) |
|
40
|
|
|
->getMock(); |
|
41
|
|
|
|
|
42
|
|
|
$this->generalDecoratorMock = $this->getMockBuilder(GeneralDecorator::class) |
|
43
|
|
|
->disableOriginalConstructor() |
|
44
|
|
|
->onlyMethods(['init', 'decorate']) |
|
45
|
|
|
->getMock(); |
|
46
|
|
|
|
|
47
|
|
|
$this->primaryDecoratorMock->expects($this->any())->method('init')->willReturnSelf(); |
|
48
|
|
|
$this->navbarDecoratorMock->expects($this->any())->method('init')->willReturnSelf(); |
|
49
|
|
|
$this->generalDecoratorMock->expects($this->any())->method('init')->willReturnSelf(); |
|
50
|
|
|
|
|
51
|
|
|
$this->sut = new Listener($this->primaryDecoratorMock, $this->navbarDecoratorMock, $this->generalDecoratorMock); |
|
52
|
|
|
|
|
53
|
|
|
parent::setUp(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testHandleCallsGeneralDecorator() |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var Navigation|MockObject $navigationMock */ |
|
59
|
|
|
$navigationMock = $this->getMockBuilder(Navigation::class) |
|
60
|
|
|
->disableOriginalConstructor() |
|
61
|
|
|
->onlyMethods(['getExtendedDescendantNodes', 'hasIntent']) |
|
62
|
|
|
->getMock(); |
|
63
|
|
|
|
|
64
|
|
|
$navigationMock->expects($this->any())->method('getExtendedDescendantNodes')->willReturn([]); |
|
65
|
|
|
$navigationMock |
|
66
|
|
|
->expects($this->at(1)) |
|
67
|
|
|
->method('hasIntent') |
|
68
|
|
|
->with(Navigation::INTENT_PRIMARY) |
|
69
|
|
|
->willReturn(false); |
|
70
|
|
|
$navigationMock |
|
71
|
|
|
->expects($this->at(2)) |
|
72
|
|
|
->method('hasIntent') |
|
73
|
|
|
->with(Navigation::INTENT_NAVBAR) |
|
74
|
|
|
->willReturn(false); |
|
75
|
|
|
|
|
76
|
|
|
$navigationReady = new NavigationReady($navigationMock); |
|
77
|
|
|
|
|
78
|
|
|
$this->generalDecoratorMock->expects($this->atLeastOnce())->method('decorate'); |
|
79
|
|
|
$this->primaryDecoratorMock->expects($this->never())->method('decorate'); |
|
80
|
|
|
$this->navbarDecoratorMock->expects($this->never())->method('decorate'); |
|
81
|
|
|
|
|
82
|
|
|
$this->sut->handle($navigationReady); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testHandleCallsPrimaryDecoratorOnPrimary() |
|
86
|
|
|
{ |
|
87
|
|
|
/** @var Navigation|MockObject $navigationMock */ |
|
88
|
|
|
$navigationMock = $this->getMockBuilder(Navigation::class) |
|
89
|
|
|
->disableOriginalConstructor() |
|
90
|
|
|
->onlyMethods(['getExtendedDescendantNodes', 'hasIntent']) |
|
91
|
|
|
->getMock(); |
|
92
|
|
|
|
|
93
|
|
|
$navigationMock |
|
94
|
|
|
->expects($this->any()) |
|
95
|
|
|
->method('getExtendedDescendantNodes') |
|
96
|
|
|
->willReturn([]); |
|
97
|
|
|
$navigationMock |
|
98
|
|
|
->expects($this->at(1)) |
|
99
|
|
|
->method('hasIntent') |
|
100
|
|
|
->with(Navigation::INTENT_PRIMARY) |
|
101
|
|
|
->willReturn(true); |
|
102
|
|
|
|
|
103
|
|
|
$navigationReady = new NavigationReady($navigationMock); |
|
104
|
|
|
|
|
105
|
|
|
$this->generalDecoratorMock->expects($this->atLeastOnce())->method('decorate'); |
|
106
|
|
|
$this->primaryDecoratorMock->expects($this->atLeastOnce())->method('decorate'); |
|
107
|
|
|
$this->navbarDecoratorMock->expects($this->never())->method('decorate'); |
|
108
|
|
|
|
|
109
|
|
|
$this->sut->handle($navigationReady); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function testHandleCallsNavbarDecoratorOnNavbar() |
|
113
|
|
|
{ |
|
114
|
|
|
/** @var Navigation|MockObject $navigationMock */ |
|
115
|
|
|
$navigationMock = $this->getMockBuilder(Navigation::class) |
|
116
|
|
|
->disableOriginalConstructor() |
|
117
|
|
|
->onlyMethods(['getExtendedDescendantNodes', 'hasIntent']) |
|
118
|
|
|
->getMock(); |
|
119
|
|
|
|
|
120
|
|
|
$navigationMock->expects($this->any())->method('getExtendedDescendantNodes')->willReturn([]); |
|
121
|
|
|
$navigationMock |
|
122
|
|
|
->expects($this->at(1)) |
|
123
|
|
|
->method('hasIntent') |
|
124
|
|
|
->with(Navigation::INTENT_PRIMARY) |
|
125
|
|
|
->willReturn(false); |
|
126
|
|
|
$navigationMock |
|
127
|
|
|
->expects($this->at(2)) |
|
128
|
|
|
->method('hasIntent') |
|
129
|
|
|
->with(Navigation::INTENT_NAVBAR) |
|
130
|
|
|
->willReturn(true); |
|
131
|
|
|
|
|
132
|
|
|
$navigationReady = new NavigationReady($navigationMock); |
|
133
|
|
|
|
|
134
|
|
|
$this->generalDecoratorMock->expects($this->atLeastOnce())->method('decorate'); |
|
135
|
|
|
$this->primaryDecoratorMock->expects($this->never())->method('decorate'); |
|
136
|
|
|
$this->navbarDecoratorMock->expects($this->atLeastOnce())->method('decorate'); |
|
137
|
|
|
|
|
138
|
|
|
$this->sut->handle($navigationReady); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|