Skip to content

Commit

Permalink
Breaking: Rename NavItem method getGroup to getGroupIdentifier
Browse files Browse the repository at this point in the history
Renames `getGroup()` to `getGroupIdentifier()` to clarify the purpose of the method.
  • Loading branch information
caendesilva committed Mar 1, 2024
1 parent 64c3e0e commit f17a412
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function getPriority(): int
*
* For sidebars this is the category key, for navigation menus this is the dropdown key.
*/
public function getGroup(): ?string
public function getGroupIdentifier(): ?string
{
return $this->group;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function addRouteToGroup(Route $route): void
{
$item = NavItem::forRoute($route);

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

$groupItem = $this->getOrCreateGroupItem($groupName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ public function __construct(TestCase $test, $sidebar = false)
public function state(): array
{
return $this->items->map(function (NavItem $item): TestNavItem {
return new TestNavItem($item->getLabel(), $item->getGroup(), $item->getPriority(), $item->getChildren());
return new TestNavItem($item->getLabel(), $item->getGroupIdentifier(), $item->getPriority(), $item->getChildren());
})->toArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function testSidebarPrioritiesCanBeSetInBothFrontMatterAndConfig()
public function testGroupCanBeSetInFrontMatter()
{
$this->makePage('foo', ['navigation.group' => 'bar']);
$this->assertEquals('bar', collect(NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems()->first()->getChildren())->first()->getGroup());
$this->assertEquals('bar', collect(NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems()->first()->getChildren())->first()->getGroupIdentifier());
}

public function testHasGroupsReturnsFalseWhenThereAreNoGroups()
Expand Down
20 changes: 10 additions & 10 deletions packages/framework/tests/Unit/NavItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function testGetPriority()
public function testGetGroup()
{
$navItem = new NavItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertNull($navItem->getGroup());
$this->assertNull($navItem->getGroupIdentifier());
}

public function testGetChildren()
Expand Down Expand Up @@ -325,28 +325,28 @@ public function testIsCurrentWithExternalRoute()

public function testGetGroupWithNoGroup()
{
$this->assertNull((new NavItem(new Route(new MarkdownPage()), 'Test', 500))->getGroup());
$this->assertNull((new NavItem(new Route(new MarkdownPage()), 'Test', 500))->getGroupIdentifier());
}

public function testGetGroupWithGroup()
{
$this->assertSame('foo', (new NavItem(new Route(new MarkdownPage()), 'Test', 500, 'foo'))->getGroup());
$this->assertSame('foo', (new NavItem(new Route(new MarkdownPage()), 'Test', 500, 'foo'))->getGroupIdentifier());
}

public function testGetGroupFromRouteWithGroup()
{
$this->assertSame('foo', NavItem::forRoute(new Route(new MarkdownPage(matter: ['navigation.group' => 'foo'])))->getGroup());
$this->assertSame('foo', NavItem::forRoute(new Route(new MarkdownPage(matter: ['navigation.group' => 'foo'])))->getGroupIdentifier());
}

public function testGetGroupForRouteWithGroup()
{
$this->assertSame('foo', NavItem::forRoute(new Route(new MarkdownPage(matter: ['navigation.group' => 'foo'])), 'foo')->getGroup());
$this->assertSame('foo', NavItem::forRoute(new Route(new MarkdownPage(matter: ['navigation.group' => 'foo'])), 'foo')->getGroupIdentifier());
}

public function testGroupKeysAreNormalized()
{
$item = new NavItem(new Route(new MarkdownPage()), 'Test', 500, 'Foo Bar');
$this->assertSame('foo-bar', $item->getGroup());
$this->assertSame('foo-bar', $item->getGroupIdentifier());
}

public function testIdentifier()
Expand Down Expand Up @@ -434,8 +434,8 @@ public function testAddingAnItemWithAGroupKeyKeepsTheSetGroupKey()

$parent->addChild($child);

$this->assertSame('foo', $parent->getGroup());
$this->assertSame('bar', $child->getGroup());
$this->assertSame('foo', $parent->getGroupIdentifier());
$this->assertSame('bar', $child->getGroupIdentifier());
}

public function testAddingAnItemWithNoGroupKeyUsesParentIdentifier()
Expand All @@ -445,7 +445,7 @@ public function testAddingAnItemWithNoGroupKeyUsesParentIdentifier()

$parent->addChild($child);

$this->assertSame('foo', $parent->getGroup());
$this->assertSame('foo', $child->getGroup());
$this->assertSame('foo', $parent->getGroupIdentifier());
$this->assertSame('foo', $child->getGroupIdentifier());
}
}

0 comments on commit f17a412

Please sign in to comment.