Skip to content

Commit

Permalink
Merge pull request #216 from hydephp/215-add-a-navitemtoroute-helper
Browse files Browse the repository at this point in the history
Add a NavItem::toRoute() helper hydephp/develop@ec64445
  • Loading branch information
github-actions committed Jul 10, 2022
1 parent e7dce76 commit e81e6aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Models/NavItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public static function toLink(string $href, string $title, int $priority = 500):
return (new self(null, $title, $priority, false))->setDestination($href);
}

/**
* Create a new navigation menu item leading to a Route model.
*/
public static function toRoute(RouteContract $route, string $title, int $priority = 500): static
{
return new self($route, $title, $priority, false);
}

/**
* Resolve a link to the navigation item.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/NavItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public function testToLink()
$this->assertFalse($item->hidden);
}

public function testToRoute()
{
$route = Route::get('index');
$item = NavItem::toRoute($route, 'foo', 10);

$this->assertSame($route, $item->route);
$this->assertSame('foo', $item->title);
$this->assertSame(10, $item->priority);
$this->assertFalse($item->hidden);
}

public function testIsCurrentRoute()
{
$route = Route::get('index');
Expand Down

0 comments on commit e81e6aa

Please sign in to comment.