Skip to content

Commit

Permalink
Fixed link generation error when using modules introduced in PR contr…
Browse files Browse the repository at this point in the history
  • Loading branch information
foxycode authored and davidkudera committed Sep 7, 2018
1 parent 13d3cd4 commit 5e8d009
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -147,7 +147,7 @@ menu:
items:
Home:
action: :Front:Home:
action: Front:Home:
visibility:
menu: true
breadcrumbs: false
Expand All @@ -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$'
Expand Down Expand Up @@ -304,7 +304,7 @@ menu:
items:
Home:
action: :Front:Home:
action: Front:Home:
Books:
link: '#'
Expand Down
6 changes: 1 addition & 5 deletions src/Carrooi/Menu/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 8 additions & 4 deletions tests/CarrooiTests/Menu/MenuItemTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
);
});
Expand All @@ -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');
})
Expand Down

0 comments on commit 5e8d009

Please sign in to comment.