diff --git a/README.md b/README.md index 86c19d1..233b19d 100644 --- a/README.md +++ b/README.md @@ -39,26 +39,26 @@ menu: items: Home: - action: :Front:Home: + action: Front:Home: Books: link: '#' items: All: - action: :Front:Books:all + action: Front:Books:all Featured: - action: :Front:Books:featured + action: Front:Books:featured admin: items: Users: - action: :Admin:Users: + action: Admin:Users: Books: - action: :Admin:Books: + action: Admin:Books: ``` ```php @@ -101,15 +101,15 @@ That structure in neon config will generate two menus: **front:** -* Home (action: `:Front:Home:`) +* Home (action: `Front:Home:`) * Books (link: `#`) - + All (action: `:Front:Books:all`) - + Featured (action: `:Front:Books:featured`) + + All (action: `Front:Books:all`) + + Featured (action: `Front:Books:featured`) **admin:** -* Users (action: `:Admin:Users:`) -* Books (action: `:Admin:Books:`) +* Users (action: `Admin:Users:`) +* Books (action: `Admin:Books:`) ## Templates @@ -147,7 +147,7 @@ menu: items: Home: - action: :Front:Home: + action: Front:Home: visibility: menu: true breadcrumbs: false @@ -165,10 +165,10 @@ menu: items: Home: - action: :Front:Home: + action: Front:Home: include: '^Front\:Home\:[a-zA-Z\:]+$' # mark as active for all actions of "Front:Home:" presenter Books: - action: :Front:Books: + action: Front:Books: include: # mark as active for actions "Front:Books:default" and "Front:Books:edit" - '^Front\:Books\:default$' - '^Front\:Books\:edit$' @@ -304,7 +304,7 @@ menu: items: Home: - action: :Front:Home: + action: Front:Home: Books: link: '#' diff --git a/src/Carrooi/Menu/MenuItem.php b/src/Carrooi/Menu/MenuItem.php index 0b158c4..5f0dbd5 100644 --- a/src/Carrooi/Menu/MenuItem.php +++ b/src/Carrooi/Menu/MenuItem.php @@ -66,11 +66,7 @@ public function isActive(): bool if ($this->getAction() && ($presenter = $this->menu->getActivePresenter())) { - try { - $presenter->link($this->getAction(), $this->getActionParameters()); - } catch (InvalidLinkException $e) {} - - if ($presenter->getLastCreatedRequestFlag('current')) { + if ($presenter->link('//this') === $this->linkGenerator->link($this)) { return $this->active = true; } diff --git a/tests/CarrooiTests/Menu/MenuItemTest.phpt b/tests/CarrooiTests/Menu/MenuItemTest.phpt index b1a5279..0ab9ab7 100644 --- a/tests/CarrooiTests/Menu/MenuItemTest.phpt +++ b/tests/CarrooiTests/Menu/MenuItemTest.phpt @@ -74,16 +74,18 @@ final class MenuItemTest extends TestCase public function testIsActive_action_current(): void { - $linkGenerator = $this->createMockLinkGenerator(); $translator = $this->createMockTranslator(); $request = $this->createMockHttpRequest(); $itemFactory = $this->createMockMenuItemFactory(); + $linkGenerator = $this->createMockLinkGenerator(function (MockInterface $linkGenerator) { + $linkGenerator->shouldReceive('link')->andReturn('#'); + }); + $menu = $this->createMockMenu(function (MockInterface $menu) { $menu->shouldReceive('getActivePresenter')->andReturn( $this->createMockPresenter(function(MockInterface $presenter) { $presenter->shouldReceive('link')->andReturn('#'); - $presenter->shouldReceive('getLastCreatedRequestFlag')->andReturn(true); }) ); }); @@ -100,16 +102,18 @@ final class MenuItemTest extends TestCase public function testIsActive_include(): void { - $linkGenerator = $this->createMockLinkGenerator(); $translator = $this->createMockTranslator(); $request = $this->createMockHttpRequest(); $itemFactory = $this->createMockMenuItemFactory(); + $linkGenerator = $this->createMockLinkGenerator(function (MockInterface $linkGenerator) { + $linkGenerator->shouldReceive('link')->andReturn('#'); + }); + $menu = $this->createMockMenu(function (MockInterface $menu) { $menu->shouldReceive('getActivePresenter')->andReturn( $this->createMockPresenter(function(MockInterface $presenter) { $presenter->shouldReceive('link')->andReturn('#'); - $presenter->shouldReceive('getLastCreatedRequestFlag')->andReturn(false); $presenter->shouldReceive('getName')->andReturn('Home'); $presenter->shouldReceive('getAction')->andReturn('edit'); })