Skip to content

Commit 76f7644

Browse files
Added the clear() method to the menu
1 parent fa10f35 commit 76f7644

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
###### 2025-XX-YY
99

1010
- Added PHP 8.4 support
11+
- Added the `clear()` method to the menu
1112

1213
### 1.11.0
1314
###### 2024-03-12

src/Menu.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public function removeItem(string $name, $removeChildren = true)
102102
return $this->items->remove($name);
103103
}
104104

105+
/** Remove all menu items from the menu */
106+
public function clear(): void
107+
{
108+
$this->items = new ItemCollection();
109+
}
110+
105111
/**
106112
* Returns menu item by name
107113
*

tests/Feature/MenuTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,17 @@ public function testAttributesAreProperlyRendered()
118118
$this->menu->render('ul')
119119
);
120120
}
121+
122+
public function testItCanDeleteAllMenuItems()
123+
{
124+
/** @var Menu $menu */
125+
$menu = \Menu::create('menu2');
126+
$menu->addItem('home', 'Home', '/');
127+
$menu->addItem('about', 'About', '/about');
128+
$menu->addItem('contact', 'Contact', '/contact');
129+
130+
$this->assertCount(3, $menu->items);
131+
$menu->clear();
132+
$this->assertCount(0, $menu->items);
133+
}
121134
}

0 commit comments

Comments
 (0)