1 | <?php |
||||
2 | |||||
3 | namespace KyleMassacre\Menus\Tests; |
||||
4 | |||||
5 | use KyleMassacre\Menus\Menu; |
||||
6 | use KyleMassacre\Menus\MenuBuilder; |
||||
7 | |||||
8 | class MenuTest extends BaseTestCase |
||||
9 | { |
||||
10 | /** |
||||
11 | * @var Menu |
||||
12 | */ |
||||
13 | private $menu; |
||||
14 | |||||
15 | public function setUp() : void |
||||
16 | { |
||||
17 | parent::setUp(); |
||||
18 | $this->menu = app(Menu::class); |
||||
19 | } |
||||
20 | /** @test */ |
||||
21 | public function it_generates_an_empty_menu() |
||||
22 | { |
||||
23 | $this->menu->create('test', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
|
|||||
24 | }); |
||||
25 | |||||
26 | $expected = <<<TEXT |
||||
27 | |||||
28 | <ul class="nav navbar-nav"> |
||||
29 | |||||
30 | </ul> |
||||
31 | |||||
32 | TEXT; |
||||
33 | |||||
34 | self::assertEquals($expected, $this->menu->get('test')); |
||||
35 | } |
||||
36 | |||||
37 | /** @test */ |
||||
38 | public function it_makes_is_an_alias_for_create() |
||||
39 | { |
||||
40 | $this->menu->make('test', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
41 | }); |
||||
42 | |||||
43 | $expected = <<<TEXT |
||||
44 | |||||
45 | <ul class="nav navbar-nav"> |
||||
46 | |||||
47 | </ul> |
||||
48 | |||||
49 | TEXT; |
||||
50 | |||||
51 | self::assertEquals($expected, $this->menu->get('test')); |
||||
52 | } |
||||
53 | |||||
54 | /** @test */ |
||||
55 | public function it_render_is_an_alias_of_get() |
||||
56 | { |
||||
57 | $this->menu->make('test', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
58 | }); |
||||
59 | |||||
60 | $expected = <<<TEXT |
||||
61 | |||||
62 | <ul class="nav navbar-nav"> |
||||
63 | |||||
64 | </ul> |
||||
65 | |||||
66 | TEXT; |
||||
67 | |||||
68 | self::assertEquals($expected, $this->menu->render('test')); |
||||
69 | } |
||||
70 | |||||
71 | /** @test */ |
||||
72 | public function it_can_get_the_instance_of_a_menu() |
||||
73 | { |
||||
74 | $this->menu->create('test', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
75 | }); |
||||
76 | |||||
77 | $this->assertInstanceOf(MenuBuilder::class, $this->menu->instance('test')); |
||||
78 | } |
||||
79 | |||||
80 | /** @test */ |
||||
81 | public function it_can_modify_a_menu_instance() |
||||
82 | { |
||||
83 | $this->menu->create('test', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
84 | }); |
||||
85 | |||||
86 | $this->menu->modify('test', function (MenuBuilder $builder) { |
||||
87 | $builder->url('hello', 'world'); |
||||
88 | }); |
||||
89 | |||||
90 | $this->assertCount(1, $this->menu->instance('test')); |
||||
0 ignored issues
–
show
$this->menu->instance('test') of type null|string is incompatible with the type Countable|iterable expected by parameter $haystack of PHPUnit\Framework\Assert::assertCount() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
91 | } |
||||
92 | |||||
93 | /** @test */ |
||||
94 | public function it_gets_a_partial_for_dropdown_styles() |
||||
95 | { |
||||
96 | $this->menu->create('test', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
97 | }); |
||||
98 | |||||
99 | $this->assertStringContainsString('.dropdown-submenu', $this->menu->style()); |
||||
100 | } |
||||
101 | |||||
102 | /** @test */ |
||||
103 | public function it_can_get_all_menus() |
||||
104 | { |
||||
105 | $this->menu->create('main', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
106 | }); |
||||
107 | $this->menu->create('footer', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
108 | }); |
||||
109 | |||||
110 | $this->assertCount(2, $this->menu->all()); |
||||
111 | } |
||||
112 | |||||
113 | /** @test */ |
||||
114 | public function it_can_count_menus() |
||||
115 | { |
||||
116 | $this->menu->create('main', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
117 | }); |
||||
118 | $this->menu->create('footer', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
119 | }); |
||||
120 | |||||
121 | $this->assertEquals(2, $this->menu->count()); |
||||
122 | } |
||||
123 | |||||
124 | /** @test */ |
||||
125 | public function it_can_destroy_all_menus() |
||||
126 | { |
||||
127 | $this->menu->create('main', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
128 | }); |
||||
129 | $this->menu->create('footer', function (MenuBuilder $menu) { |
||||
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
130 | }); |
||||
131 | |||||
132 | $this->assertCount(2, $this->menu->all()); |
||||
133 | $this->menu->destroy(); |
||||
134 | $this->assertCount(0, $this->menu->all()); |
||||
135 | } |
||||
136 | |||||
137 | /** @test */ |
||||
138 | public function it_still_generates_empty_menu_after_adding_dropdown() |
||||
139 | { |
||||
140 | $this->menu->create('test', function (MenuBuilder $menu) { |
||||
141 | $menu->dropdown('Test', function ($sub) { |
||||
0 ignored issues
–
show
The parameter
$sub is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
142 | |||||
143 | })->hideWhen(function () { |
||||
144 | return true; |
||||
145 | }); |
||||
146 | }); |
||||
147 | |||||
148 | $expected = <<<TEXT |
||||
149 | |||||
150 | <ul class="nav navbar-nav"> |
||||
151 | |||||
152 | </ul> |
||||
153 | |||||
154 | TEXT; |
||||
155 | |||||
156 | self::assertEquals($expected, $this->menu->get('test')); |
||||
157 | } |
||||
158 | |||||
159 | /** @test */ |
||||
160 | public function it_still_generates_empty_menu_after_adding_item() |
||||
161 | { |
||||
162 | $this->menu->create('test', function (MenuBuilder $menu) { |
||||
163 | $menu->url('/', 'Test') |
||||
164 | ->hideWhen(function () { |
||||
165 | return true; |
||||
166 | }); |
||||
167 | }); |
||||
168 | |||||
169 | $expected = <<<TEXT |
||||
170 | |||||
171 | <ul class="nav navbar-nav"> |
||||
172 | |||||
173 | </ul> |
||||
174 | |||||
175 | TEXT; |
||||
176 | |||||
177 | self::assertEquals($expected, $this->menu->get('test')); |
||||
178 | } |
||||
179 | } |
||||
180 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.