Skip to content

Commit

Permalink
Breaking: Make NavItem::$destination property protected
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Feb 19, 2024
1 parent 26b2632 commit e2a8f36
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
: 'active bg-black/5 dark:bg-black/10' => $item->isCurrent()
]) role="listitem">
@if($item->isCurrent())
<a href="{{ $item->destination }}" aria-current="true" @class([$grouped
<a href="{{ $item->getDestination() }}" aria-current="true" @class([$grouped
? '-ml-8 pl-4 py-1 px-2 block text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out hover:bg-black/10'
: '-ml-4 p-2 block hover:bg-black/5 dark:hover:bg-black/10 text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out'
])>
@@ -17,7 +17,7 @@
{!! ($page->getTableOfContents()) !!}
@endif
@else
<a href="{{ $item->destination }}" @class([$grouped
<a href="{{ $item->getDestination() }}" @class([$grouped
? '-ml-8 pl-4 py-1 px-2 block border-l-[0.325rem] border-transparent transition-colors duration-300 ease-in-out hover:bg-black/10'
: 'block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10'
])>
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
*/
class NavItem implements Stringable
{
public Route $destination;
protected Route $destination;
public string $label;
public int $priority;
public ?string $group;
30 changes: 15 additions & 15 deletions packages/framework/tests/Unit/NavItemTest.php
Original file line number Diff line number Diff line change
@@ -44,36 +44,36 @@ public function testConstruct()
$route = new Route(new MarkdownPage());
$item = new NavItem($route, 'Test', 500);

$this->assertSame($route, $item->destination);
$this->assertSame($route, $item->getDestination());
}

public function testPassingRouteInstanceToConstructorUsesRouteInstance()
{
$route = new Route(new MarkdownPage());
$this->assertSame($route, (new NavItem($route, 'Home'))->destination);
$this->assertSame($route, (new NavItem($route, 'Home'))->getDestination());
}

public function testPassingRouteKeyToConstructorUsesRouteInstance()
{
$route = Routes::get('index');

$this->assertSame($route, (new NavItem('index', 'Home'))->destination);
$this->assertSame($route, (new NavItem('index', 'Home'))->getDestination());
}

public function testPassingUrlToConstructorUsesExternalRoute()
{
$item = new NavItem('https://example.com', 'Home');
$this->assertInstanceOf(ExternalRoute::class, $item->destination);
$this->assertEquals(new ExternalRoute('https://example.com'), $item->destination);
$this->assertSame('https://example.com', (string) $item->destination);
$this->assertInstanceOf(ExternalRoute::class, $item->getDestination());
$this->assertEquals(new ExternalRoute('https://example.com'), $item->getDestination());
$this->assertSame('https://example.com', (string) $item->getDestination());
}

public function testPassingUnknownRouteKeyToConstructorUsesExternalRoute()
{
$item = new NavItem('foo', 'Home');
$this->assertInstanceOf(ExternalRoute::class, $item->destination);
$this->assertEquals(new ExternalRoute('foo'), $item->destination);
$this->assertSame('foo', (string) $item->destination);
$this->assertInstanceOf(ExternalRoute::class, $item->getDestination());
$this->assertEquals(new ExternalRoute('foo'), $item->getDestination());
$this->assertSame('foo', (string) $item->getDestination());
}

public function testCanConstructWithChildren()
@@ -86,7 +86,7 @@ public function testCanConstructWithChildren()
$item = new NavItem($route, 'Test', 500, null, $children);

$this->assertSame('Test', $item->label);
$this->assertSame($route, $item->destination);
$this->assertSame($route, $item->getDestination());
$this->assertSame(500, $item->priority);

$this->assertCount(2, $item->children);
@@ -111,7 +111,7 @@ public function testCanConstructWithChildrenWithoutRoute()
$item = new NavItem('', 'Test', 500, null, $children);

$this->assertSame('Test', $item->label);
$this->assertSame('', $item->destination->getLink());
$this->assertSame('', $item->getDestination()->getLink());

$this->assertCount(2, $item->children);
$this->assertSame($children, $item->children);
@@ -171,7 +171,7 @@ public function testFromRoute()
$route = new Route(new MarkdownPage());
$item = NavItem::fromRoute($route);

$this->assertSame($route, $item->destination);
$this->assertSame($route, $item->getDestination());
}

public function testToString()
@@ -185,7 +185,7 @@ public function testForLink()
{
$item = NavItem::forLink('foo', 'bar');

$this->assertEquals(new ExternalRoute('foo'), $item->destination);
$this->assertEquals(new ExternalRoute('foo'), $item->getDestination());
$this->assertSame('bar', $item->label);
$this->assertSame(500, $item->priority);
}
@@ -200,7 +200,7 @@ public function testForRoute()
$route = Routes::get('404');
$item = NavItem::forRoute($route, 'foo');

$this->assertSame($route, $item->destination);
$this->assertSame($route, $item->getDestination());
$this->assertSame('foo', $item->label);
$this->assertSame(999, $item->priority);
}
@@ -210,7 +210,7 @@ public function testForIndexRoute()
$route = Routes::get('index');
$item = NavItem::forRoute($route, 'foo');

$this->assertSame($route, $item->destination);
$this->assertSame($route, $item->getDestination());
$this->assertSame('foo', $item->label);
$this->assertSame(0, $item->priority);
}

0 comments on commit e2a8f36

Please sign in to comment.