Skip to content

Commit

Permalink
Replace all usages of fromRoute with forRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Feb 29, 2024
1 parent 870e004 commit 1edb2f2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ protected function generate(): void
if ($this->canGroupRoute($route)) {
$this->addRouteToGroup($route);
} else {
$this->items->put($route->getRouteKey(), NavItem::fromRoute($route));
$this->items->put($route->getRouteKey(), NavItem::forRoute($route));
}
}
});

if ($this->generatesSidebar) {
// If there are no pages other than the index page, we add it to the sidebar so that it's not empty
if ($this->items->count() === 0 && DocumentationPage::home() !== null) {
$this->items->push(NavItem::fromRoute(DocumentationPage::home()));
$this->items->push(NavItem::forRoute(DocumentationPage::home()));
}
} else {
collect(Config::getArray('hyde.navigation.custom', []))->each(function (NavItem $item): void {
Expand Down Expand Up @@ -133,7 +133,7 @@ protected function canGroupRoute(Route $route): bool

protected function addRouteToGroup(Route $route): void
{
$item = NavItem::fromRoute($route);
$item = NavItem::forRoute($route);

$groupName = $this->generatesSidebar ? ($item->getGroup() ?? 'Other') : $item->getGroup();

Expand Down
44 changes: 22 additions & 22 deletions packages/framework/tests/Feature/NavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testGenerateMethodCreatesCollectionOfNavItems()
public function testGetItemsReturnsItems()
{
$this->assertEquals(collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('index')),
]), $this->createNavigationMenu()->getItems());
}

Expand Down Expand Up @@ -67,9 +67,9 @@ public function testCreatedCollectionIsSortedByNavigationMenuPriority()
$menu = $this->createNavigationMenu();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::fromRoute(Routes::get('foo')),
NavItem::fromRoute(Routes::get('docs/index')),
NavItem::forRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('foo')),
NavItem::forRoute(Routes::get('docs/index')),
]);

$this->assertCount(count($expected), $menu->getItems());
Expand All @@ -83,8 +83,8 @@ public function testIsSortedAutomaticallyWhenUsingNavigationMenuCreate()
$menu = $this->createNavigationMenu();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::fromRoute(Routes::get('foo')),
NavItem::forRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('foo')),
]);

$this->assertCount(count($expected), $menu->getItems());
Expand All @@ -98,7 +98,7 @@ public function testExternalLinkCanBeAddedInConfig()
$menu = $this->createNavigationMenu();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('index')),
NavItem::forLink('https://example.com', 'foo'),
]);

Expand All @@ -113,7 +113,7 @@ public function testPathLinkCanBeAddedInConfig()
$menu = $this->createNavigationMenu();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('index')),
NavItem::forLink('foo', 'foo'),
]);

Expand All @@ -131,7 +131,7 @@ public function testDuplicatesAreNotRemovedWhenAddingInConfig()
$menu = $this->createNavigationMenu();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('index')),
NavItem::forLink('foo', 'foo'),
NavItem::forLink('foo', 'foo'),
]);
Expand All @@ -150,7 +150,7 @@ public function testDuplicatesAreNotRemovedWhenAddingInConfigRegardlessOfDestina
$menu = $this->createNavigationMenu();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('index')),
NavItem::forLink('foo', 'foo'),
NavItem::forLink('bar', 'foo'),
]);
Expand All @@ -168,9 +168,9 @@ public function testConfigItemsTakePrecedenceOverGeneratedItems()
$menu = $this->createNavigationMenu();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('index')),
NavItem::forLink('bar', 'Foo'),
NavItem::fromRoute(Routes::get('foo')),
NavItem::forRoute(Routes::get('foo')),
]);

$this->assertCount(count($expected), $menu->getItems());
Expand All @@ -185,8 +185,8 @@ public function testDocumentationPagesThatAreNotIndexAreNotAddedToTheMenu()
$menu = $this->createNavigationMenu();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::fromRoute(Routes::get('docs/index')),
NavItem::forRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('docs/index')),
]);

$this->assertCount(count($expected), $menu->getItems());
Expand All @@ -199,7 +199,7 @@ public function testPagesInSubdirectoriesAreNotAddedToTheNavigationMenu()
$this->file('_pages/foo/bar.md');

$menu = $this->createNavigationMenu();
$expected = collect([NavItem::fromRoute(Routes::get('index'))]);
$expected = collect([NavItem::forRoute(Routes::get('index'))]);

$this->assertCount(count($expected), $menu->getItems());
$this->assertEquals($expected, $menu->getItems());
Expand All @@ -213,8 +213,8 @@ public function testPagesInSubdirectoriesCanBeAddedToTheNavigationMenuWithConfig

$menu = $this->createNavigationMenu();
$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::fromRoute(Routes::get('foo/bar')),
NavItem::forRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('foo/bar')),
]);

$this->assertCount(count($expected), $menu->getItems());
Expand All @@ -229,9 +229,9 @@ public function testPagesInSubdirectoriesAreNotAddedToTheNavigationMenuWithConfi

$menu = $this->createNavigationMenu();
$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forRoute(Routes::get('index')),
NavItem::forGroup('Foo', [
NavItem::fromRoute(Routes::get('foo/bar')),
NavItem::forRoute(Routes::get('foo/bar')),
]),
]);

Expand All @@ -249,10 +249,10 @@ public function testPagesInDropdownsDoNotGetAddedToTheMainNavigation()

$this->assertCount(3, $menu->getItems());
$this->assertEquals([
NavItem::fromRoute(Routes::get('index')),
NavItem::fromRoute((new MarkdownPage('foo'))->getRoute()),
NavItem::forRoute(Routes::get('index')),
NavItem::forRoute((new MarkdownPage('foo'))->getRoute()),
NavItem::forGroup('Bar', [
NavItem::fromRoute((new MarkdownPage('bar/baz'))->getRoute()),
NavItem::forRoute((new MarkdownPage('bar/baz'))->getRoute()),
]),
], $menu->getItems()->all());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public function testSidebarIsOrderedAlphabeticallyWhenNoOrderIsSetInConfig()

$this->assertEquals(
collect([
NavItem::fromRoute(Routes::get('docs/a'), priority: 999),
NavItem::fromRoute(Routes::get('docs/b'), priority: 999),
NavItem::fromRoute(Routes::get('docs/c'), priority: 999),
NavItem::forRoute(Routes::get('docs/a'), priority: 999),
NavItem::forRoute(Routes::get('docs/b'), priority: 999),
NavItem::forRoute(Routes::get('docs/c'), priority: 999),
]),
NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems()
);
Expand All @@ -107,9 +107,9 @@ public function testSidebarIsOrderedByPriorityWhenPriorityIsSetInConfig()

$this->assertEquals(
collect([
NavItem::fromRoute(Routes::get('docs/c'), priority: 250 + 250),
NavItem::fromRoute(Routes::get('docs/b'), priority: 250 + 251),
NavItem::fromRoute(Routes::get('docs/a'), priority: 250 + 252),
NavItem::forRoute(Routes::get('docs/c'), priority: 250 + 250),
NavItem::forRoute(Routes::get('docs/b'), priority: 250 + 251),
NavItem::forRoute(Routes::get('docs/a'), priority: 250 + 252),
]),
NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems()
);
Expand Down Expand Up @@ -146,9 +146,9 @@ public function testSidebarPrioritiesCanBeSetInBothFrontMatterAndConfig()

$this->assertEquals(
collect([
NavItem::fromRoute(Routes::get('docs/first'), priority: 250 + 250),
NavItem::fromRoute(Routes::get('docs/second'), priority: 250 + 252),
NavItem::fromRoute(Routes::get('docs/third'), priority: 250 + 300),
NavItem::forRoute(Routes::get('docs/first'), priority: 250 + 250),
NavItem::forRoute(Routes::get('docs/second'), priority: 250 + 252),
NavItem::forRoute(Routes::get('docs/third'), priority: 250 + 300),
]),
NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems()
);
Expand Down Expand Up @@ -195,7 +195,7 @@ public function testGetItemsInGroupDoesNotIncludeDocsIndex()
Filesystem::touch('_docs/index.md');

$this->assertEquals(
collect([NavItem::fromRoute(Routes::get('docs/foo'), priority: 999)]),
collect([NavItem::forRoute(Routes::get('docs/foo'), priority: 999)]),
NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems()
);
}
Expand Down Expand Up @@ -268,10 +268,10 @@ public function testCanHaveMultipleGroupedPagesWithTheSameNameLabels()
$this->assertEquals(
collect([
NavItem::forGroup('Bar', [
NavItem::fromRoute(Routes::get('docs/bar'), priority: 999),
NavItem::forRoute(Routes::get('docs/bar'), priority: 999),
]),
NavItem::forGroup('Foo', [
NavItem::fromRoute(Routes::get('docs/foo'), priority: 999),
NavItem::forRoute(Routes::get('docs/foo'), priority: 999),
]),
]),
$sidebar->getItems()
Expand All @@ -289,8 +289,8 @@ public function testDuplicateLabelsWithinTheSameGroupAreNotRemoved()
$this->assertEquals(
collect([
NavItem::forGroup('Foo', [
NavItem::fromRoute(Routes::get('docs/bar'), priority: 999),
NavItem::fromRoute(Routes::get('docs/foo'), priority: 999),
NavItem::forRoute(Routes::get('docs/bar'), priority: 999),
NavItem::forRoute(Routes::get('docs/foo'), priority: 999),
]),
]),
$sidebar->getItems()
Expand All @@ -312,7 +312,7 @@ public function testIndexPageAddedToSidebarWhenItIsTheOnlyPage()

$this->assertCount(1, $sidebar->getItems());
$this->assertEquals(
collect([NavItem::fromRoute(Routes::get('docs/index'))]),
collect([NavItem::forRoute(Routes::get('docs/index'))]),
$sidebar->getItems()
);
}
Expand All @@ -325,7 +325,7 @@ public function testIndexPageNotAddedToSidebarWhenOtherPagesExist()

$this->assertCount(1, $sidebar->getItems());
$this->assertEquals(
collect([NavItem::fromRoute(Routes::get('docs/test-0'))]),
collect([NavItem::forRoute(Routes::get('docs/test-0'))]),
$sidebar->getItems()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function testHasGroupsReturnsTrueWhenAtLeastOneItemHasChildren()
$page = new DocumentationPage('foo');
$child = new DocumentationPage('bar');
$menu = new DocumentationSidebar([
NavItem::fromRoute($page->getRoute())->addChild(NavItem::fromRoute($child->getRoute())),
NavItem::forRoute($page->getRoute())->addChild(NavItem::forRoute($child->getRoute())),
]);

$this->assertTrue($menu->hasGroups());
Expand Down
26 changes: 13 additions & 13 deletions packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ protected function tearDown(): void
public function testIsCurrent()
{
$this->mockRenderData($this->makeRoute('foo'));
$this->assertFalse(NavItem::fromRoute($this->makeRoute('bar'))->isCurrent());
$this->assertFalse(NavItem::forRoute($this->makeRoute('bar'))->isCurrent());
}

public function testIsCurrentWhenCurrent()
{
$this->mockRenderData($this->makeRoute('foo'));
$this->assertTrue(NavItem::fromRoute($this->makeRoute('foo'))->isCurrent());
$this->assertTrue(NavItem::forRoute($this->makeRoute('foo'))->isCurrent());
}

public function testIsCurrentUsingCurrentRoute()
{
$this->mockRenderData($this->makeRoute('index'));
$this->assertTrue(NavItem::fromRoute(Routes::get('index'))->isCurrent());
$this->assertTrue(NavItem::forRoute(Routes::get('index'))->isCurrent());
}

public function testIsCurrentUsingCurrentLink()
Expand All @@ -58,13 +58,13 @@ public function testIsCurrentUsingCurrentLink()
public function testIsCurrentWhenNotCurrent()
{
$this->mockRenderData($this->makeRoute('foo'));
$this->assertFalse(NavItem::fromRoute($this->makeRoute('bar'))->isCurrent());
$this->assertFalse(NavItem::forRoute($this->makeRoute('bar'))->isCurrent());
}

public function testIsCurrentUsingNotCurrentRoute()
{
$this->mockRenderData($this->makeRoute('foo'));
$this->assertFalse(NavItem::fromRoute(Routes::get('index'))->isCurrent());
$this->assertFalse(NavItem::forRoute(Routes::get('index'))->isCurrent());
}

public function testIsCurrentUsingNotCurrentLink()
Expand All @@ -76,49 +76,49 @@ public function testIsCurrentUsingNotCurrentLink()
public function testIsCurrentWithNestedCurrentPage()
{
$this->mockRenderData($this->makeRoute('foo/bar'));
$this->assertFalse(NavItem::fromRoute($this->makeRoute('bar'))->isCurrent());
$this->assertFalse(NavItem::forRoute($this->makeRoute('bar'))->isCurrent());
}

public function testIsCurrentWhenCurrentWithNestedCurrentPage()
{
$this->mockRenderData($this->makeRoute('foo/bar'));
$this->assertTrue(NavItem::fromRoute($this->makeRoute('foo/bar'))->isCurrent());
$this->assertTrue(NavItem::forRoute($this->makeRoute('foo/bar'))->isCurrent());
}

public function testIsCurrentWithNestedCurrentPageWhenNested()
{
$this->mockRenderData($this->makeRoute('foo/bar'));
$this->assertTrue(NavItem::fromRoute($this->makeRoute('foo/bar'))->isCurrent());
$this->assertTrue(NavItem::forRoute($this->makeRoute('foo/bar'))->isCurrent());
}

public function testIsCurrentWhenCurrentWithNestedCurrentPageWhenNested()
{
$this->mockRenderData($this->makeRoute('foo/bar'));
$this->assertFalse(NavItem::fromRoute($this->makeRoute('foo/baz'))->isCurrent());
$this->assertFalse(NavItem::forRoute($this->makeRoute('foo/baz'))->isCurrent());
}

public function testIsCurrentWithNestedCurrentPageWhenVeryNested()
{
$this->mockRenderData($this->makeRoute('foo/bar/baz'));
$this->assertTrue(NavItem::fromRoute($this->makeRoute('foo/bar/baz'))->isCurrent());
$this->assertTrue(NavItem::forRoute($this->makeRoute('foo/bar/baz'))->isCurrent());
}

public function testIsCurrentWhenCurrentWithNestedCurrentPageWhenVeryNested()
{
$this->mockRenderData($this->makeRoute('foo/bar/baz'));
$this->assertFalse(NavItem::fromRoute($this->makeRoute('foo/baz/bar'))->isCurrent());
$this->assertFalse(NavItem::forRoute($this->makeRoute('foo/baz/bar'))->isCurrent());
}

public function testIsCurrentWithNestedCurrentPageWhenVeryDifferingNested()
{
$this->mockRenderData($this->makeRoute('foo'));
$this->assertFalse(NavItem::fromRoute($this->makeRoute('foo/bar/baz'))->isCurrent());
$this->assertFalse(NavItem::forRoute($this->makeRoute('foo/bar/baz'))->isCurrent());
}

public function testIsCurrentWithNestedCurrentPageWhenVeryDifferingNestedInverse()
{
$this->mockRenderData($this->makeRoute('foo/bar/baz'));
$this->assertFalse(NavItem::fromRoute($this->makeRoute('foo'))->isCurrent());
$this->assertFalse(NavItem::forRoute($this->makeRoute('foo'))->isCurrent());
}

public function testIsCurrentUsingCurrentLinkWithNestedCurrentPage()
Expand Down
Loading

0 comments on commit 1edb2f2

Please sign in to comment.