|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests; |
|
4
|
|
|
|
|
5
|
|
|
use JumpGate\Menu\Container; |
|
6
|
|
|
use JumpGate\Menu\DropDown; |
|
7
|
|
|
use JumpGate\Menu\Link; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class ContainerTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var \JumpGate\Menu\Container |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $menu; |
|
16
|
|
|
|
|
17
|
16 |
|
public function setUp() |
|
18
|
|
|
{ |
|
19
|
16 |
|
parent::setUp(); |
|
20
|
|
|
|
|
21
|
16 |
|
$this->menu = new Container(); |
|
22
|
16 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** @test */ |
|
25
|
1 |
|
public function it_adds_a_menu() |
|
26
|
|
|
{ |
|
27
|
1 |
|
$menu = $this->menu->getMenu('menuName'); |
|
28
|
|
|
|
|
29
|
1 |
|
$this->assertInstanceOf('\Jumpgate\Menu\Menu', $menu); |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** @test */ |
|
33
|
1 |
|
public function it_checks_if_menu_exists_returns_false() |
|
34
|
|
|
{ |
|
35
|
1 |
|
$this->assertFalse($this->menu->exists('menuName')); |
|
36
|
1 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** @test */ |
|
39
|
1 |
|
public function it_checks_if_menu_exists_returns_true() |
|
40
|
|
|
{ |
|
41
|
1 |
|
$menu = $this->menu->getMenu('menuName'); |
|
42
|
|
|
|
|
43
|
1 |
|
$this->assertInstanceOf('\Jumpgate\Menu\Menu', $menu); |
|
44
|
1 |
|
$this->assertTrue($this->menu->exists('menuName')); |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** @test */ |
|
48
|
1 |
|
public function it_checks_if_has_links_return_true() |
|
49
|
|
|
{ |
|
50
|
1 |
|
$this->menu->getMenu('menuName') |
|
51
|
1 |
|
->link('slug', function () { |
|
52
|
|
|
// |
|
53
|
1 |
|
}); |
|
54
|
|
|
|
|
55
|
1 |
|
$this->assertTrue($this->menu->hasLinks('menuName')); |
|
56
|
1 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** @test */ |
|
59
|
1 |
|
public function it_checks_if_has_links_return_false() |
|
60
|
|
|
{ |
|
61
|
1 |
|
$menu = $this->menu->getMenu('menuName'); |
|
62
|
|
|
|
|
63
|
1 |
|
$this->assertInstanceOf('\Jumpgate\Menu\Menu', $menu); |
|
64
|
1 |
|
$this->assertFalse($this->menu->hasLinks('menuName')); |
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** @test */ |
|
68
|
1 |
|
public function it_checks_set_active() |
|
69
|
|
|
{ |
|
70
|
1 |
|
$this->menu->setActive('slug'); |
|
71
|
|
|
|
|
72
|
1 |
|
$this->assertEquals('slug', $this->menu->getActive()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** @test */ |
|
76
|
1 |
|
public function it_checks_if_get_menu_returns_the_existing_menu() |
|
77
|
|
|
{ |
|
78
|
1 |
|
$this->menu->getMenu('menuName') |
|
79
|
1 |
|
->link('slug', function () { |
|
80
|
|
|
// |
|
81
|
1 |
|
}); |
|
82
|
|
|
|
|
83
|
1 |
|
$this->assertCount(1, $this->menu->getMenu('menuName')->links); |
|
84
|
1 |
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @test |
|
88
|
|
|
* |
|
89
|
|
|
* @expectedException Exception |
|
90
|
|
|
* @expectedExceptionMessage Menu test not found. |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public function it_throws_an_exception_if_render_cant_find_the_menu() |
|
93
|
|
|
{ |
|
94
|
1 |
|
$this->menu->render('test'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** @test */ |
|
98
|
1 |
|
public function it_can_render_a_menu() |
|
99
|
|
|
{ |
|
100
|
1 |
|
$this->menu->getMenu('test') |
|
101
|
1 |
|
->link('slug', function () { |
|
102
|
|
|
// |
|
103
|
1 |
|
}); |
|
104
|
|
|
|
|
105
|
1 |
|
$this->assertInstanceOf('\Jumpgate\Menu\Menu', $this->menu->render('test')); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** @test */ |
|
109
|
1 |
|
public function it_sets_active_items() |
|
110
|
|
|
{ |
|
111
|
1 |
|
$this->menu->getMenu('test') |
|
112
|
1 |
|
->link('slug', function () { |
|
113
|
|
|
// |
|
114
|
1 |
|
}); |
|
115
|
|
|
|
|
116
|
1 |
|
$this->menu->setActive('slug'); |
|
117
|
|
|
|
|
118
|
1 |
|
$menu = $this->menu->render('test'); |
|
119
|
|
|
|
|
120
|
1 |
|
$this->assertTrue($menu->links->first()->active); |
|
121
|
1 |
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** @test */ |
|
124
|
1 |
View Code Duplication |
public function it_sets_active_items_in_dropdown() |
|
125
|
|
|
{ |
|
126
|
1 |
|
$this->menu->getMenu('test') |
|
127
|
|
|
->dropdown('slug', 'name', function (DropDown $dropdown) { |
|
128
|
1 |
|
$dropdown->link('slug2', function () { |
|
129
|
|
|
// |
|
130
|
1 |
|
}); |
|
131
|
1 |
|
}); |
|
132
|
|
|
|
|
133
|
1 |
|
$this->menu->setActive('slug2'); |
|
134
|
|
|
|
|
135
|
1 |
|
$menu = $this->menu->render('test'); |
|
136
|
|
|
|
|
137
|
1 |
|
$this->assertTrue($menu->links->first()->active); |
|
138
|
1 |
|
$this->assertTrue($menu->links->first()->links->first()->active); |
|
139
|
1 |
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** @test */ |
|
142
|
1 |
View Code Duplication |
public function it_sets_active_items_in_dropdown_without_parentage() |
|
143
|
|
|
{ |
|
144
|
1 |
|
$this->menu->getMenu('test') |
|
145
|
1 |
|
->dropdown('slug', 'name', function (DropDown $dropdown) { |
|
146
|
1 |
|
$dropdown->disableActiveParentage(); |
|
147
|
|
|
|
|
148
|
1 |
|
$dropdown->link('slug2', function () { |
|
149
|
|
|
// |
|
150
|
1 |
|
}); |
|
151
|
1 |
|
}); |
|
152
|
|
|
|
|
153
|
1 |
|
$this->menu->setActive('slug2'); |
|
154
|
|
|
|
|
155
|
1 |
|
$menu = $this->menu->render('test'); |
|
156
|
|
|
|
|
157
|
1 |
|
$this->assertFalse($menu->links->first()->active); |
|
158
|
1 |
|
$this->assertTrue($menu->links->first()->links->first()->active); |
|
159
|
1 |
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** @test */ |
|
162
|
1 |
|
public function it_tests_insert_before_link() |
|
163
|
|
|
{ |
|
164
|
1 |
|
$menu = $this->menu->getMenu('test'); |
|
165
|
|
|
|
|
166
|
1 |
|
$menu->link('slug', function () { |
|
167
|
|
|
// |
|
168
|
1 |
|
}); |
|
169
|
|
|
|
|
170
|
1 |
|
$menu->link('slug2', function (Link $link) { |
|
171
|
1 |
|
$link->insertBefore('slug'); |
|
172
|
1 |
|
}); |
|
173
|
|
|
|
|
174
|
1 |
|
$this->assertEquals('slug2', $menu->links->first()->slug); |
|
175
|
1 |
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** @test */ |
|
178
|
1 |
View Code Duplication |
public function it_tests_insert_before_dropdown() |
|
179
|
|
|
{ |
|
180
|
1 |
|
$menu = $this->menu->getMenu('test'); |
|
181
|
|
|
|
|
182
|
|
|
$menu->dropdown('slug', 'name', function (DropDown $dropdown) { |
|
183
|
1 |
|
$dropdown->link('slug2', function () { |
|
184
|
|
|
// |
|
185
|
1 |
|
}); |
|
186
|
1 |
|
}); |
|
187
|
|
|
|
|
188
|
1 |
|
$menu->link('slug3', function ($link) { |
|
189
|
1 |
|
$link->insertBefore('slug2'); |
|
190
|
1 |
|
}); |
|
191
|
|
|
|
|
192
|
1 |
|
$this->assertEquals('slug3', $menu->links->first()->links->first()->slug); |
|
193
|
1 |
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** @test */ |
|
196
|
1 |
View Code Duplication |
public function it_tests_insert_after_link() |
|
197
|
|
|
{ |
|
198
|
1 |
|
$menu = $this->menu->getMenu('test'); |
|
199
|
|
|
|
|
200
|
1 |
|
$menu->link('slug', function () { |
|
201
|
|
|
// |
|
202
|
1 |
|
}); |
|
203
|
|
|
|
|
204
|
1 |
|
$menu->link('slug2', function () { |
|
205
|
|
|
// |
|
206
|
1 |
|
}); |
|
207
|
|
|
|
|
208
|
1 |
|
$menu->link('slug3', function () { |
|
209
|
|
|
// |
|
210
|
1 |
|
}); |
|
211
|
|
|
|
|
212
|
1 |
|
$menu->link('slug4', function (Link $link) { |
|
213
|
1 |
|
$link->insertAfter('slug2'); |
|
214
|
1 |
|
}); |
|
215
|
|
|
|
|
216
|
1 |
|
$this->assertEquals('slug4', $menu->links->get(2)->slug); |
|
217
|
1 |
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** @test */ |
|
220
|
1 |
|
public function it_tests_insert_after_dropdown() |
|
221
|
|
|
{ |
|
222
|
1 |
|
$menu = $this->menu->getMenu('test'); |
|
223
|
|
|
|
|
224
|
|
|
$menu->dropdown('slug', 'name', function (DropDown $dropdown) { |
|
225
|
1 |
|
$dropdown->link('slug2', function () { |
|
226
|
|
|
// |
|
227
|
1 |
|
}); |
|
228
|
1 |
|
$dropdown->link('slug3', function () { |
|
229
|
|
|
// |
|
230
|
1 |
|
}); |
|
231
|
1 |
|
$dropdown->link('slug4', function () { |
|
232
|
|
|
// |
|
233
|
1 |
|
}); |
|
234
|
1 |
|
}); |
|
235
|
|
|
|
|
236
|
1 |
|
$menu->link('slug5', function (Link $link) { |
|
237
|
1 |
|
$link->insertAfter('slug2'); |
|
238
|
1 |
|
}); |
|
239
|
|
|
|
|
240
|
|
|
$this->assertEquals('slug5', $menu->links->first()->links->get(1)->slug); |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|