fix: keep menu items in parent cycles, tighten menu write tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
@@ -26,23 +26,39 @@ final class MenuAssignLocationAbilityTest extends TestCase
|
||||
{
|
||||
Functions\expect('set_theme_mod')->once()->with('nav_menu_locations', ['primary-menu' => 8]);
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->expects('record')->andReturn(6);
|
||||
$log->expects('record')
|
||||
->with(
|
||||
'lit/menu-assign-location',
|
||||
'menu_location',
|
||||
'primary-menu',
|
||||
'Menü 8 der Position primary-menu zugewiesen'
|
||||
)
|
||||
->andReturn(6);
|
||||
|
||||
$result = (new MenuAssignLocationAbility($log))->execute(['location' => 'primary-menu', 'menu_id' => 8]);
|
||||
|
||||
self::assertSame(3, $result['previous_menu_id']);
|
||||
self::assertSame('assigned', $result['changed'][0]['action']);
|
||||
self::assertSame(6, $result['log_id']);
|
||||
}
|
||||
|
||||
public function testZeroRemovesTheAssignment(): void
|
||||
{
|
||||
Functions\expect('set_theme_mod')->once()->with('nav_menu_locations', []);
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->expects('record')->andReturn(7);
|
||||
$log->expects('record')
|
||||
->with(
|
||||
'lit/menu-assign-location',
|
||||
'menu_location',
|
||||
'primary-menu',
|
||||
'Zuweisung der Position primary-menu entfernt'
|
||||
)
|
||||
->andReturn(7);
|
||||
|
||||
$result = (new MenuAssignLocationAbility($log))->execute(['location' => 'primary-menu', 'menu_id' => 0]);
|
||||
|
||||
self::assertSame('unassigned', $result['changed'][0]['action']);
|
||||
self::assertSame(7, $result['log_id']);
|
||||
}
|
||||
|
||||
public function testUnknownMenuIsNotFound(): void
|
||||
@@ -54,4 +70,14 @@ final class MenuAssignLocationAbilityTest extends TestCase
|
||||
|
||||
self::assertSame('lit_not_found', $result->get_error_code());
|
||||
}
|
||||
|
||||
public function testPermissionNeedsThemeOptionRights(): void
|
||||
{
|
||||
Functions\when('current_user_can')->justReturn(false);
|
||||
|
||||
$ability = new MenuAssignLocationAbility(Mockery::mock(ChangeLog::class));
|
||||
$input = ['location' => 'primary-menu', 'menu_id' => 8];
|
||||
|
||||
self::assertSame('lit_forbidden', $ability->permission($input)->get_error_code());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,5 +54,15 @@ final class MenuCreateAbilityTest extends TestCase
|
||||
|
||||
self::assertSame(8, $result['menu_id']);
|
||||
self::assertSame('created', $result['changed'][0]['action']);
|
||||
self::assertSame(5, $result['log_id']);
|
||||
}
|
||||
|
||||
public function testPermissionNeedsThemeOptionRights(): void
|
||||
{
|
||||
Functions\when('current_user_can')->justReturn(false);
|
||||
|
||||
$ability = new MenuCreateAbility(Mockery::mock(ChangeLog::class));
|
||||
|
||||
self::assertSame('lit_forbidden', $ability->permission(['name' => 'Neu'])->get_error_code());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,4 +34,21 @@ final class MenuTreeTest extends TestCase
|
||||
|
||||
self::assertSame(['Waise', 'Zirkel'], array_column($tree, 'title'));
|
||||
}
|
||||
|
||||
public function testParentNotPresentInTheMenuLandsOnTheTopLevel(): void
|
||||
{
|
||||
$tree = MenuTree::build([self::item(40, 12345, 'Verwaist')]);
|
||||
|
||||
self::assertSame(['Verwaist'], array_column($tree, 'title'));
|
||||
self::assertSame([], $tree[0]['children']);
|
||||
}
|
||||
|
||||
public function testATwoNodeParentCycleKeepsBothItemsOnTheTopLevel(): void
|
||||
{
|
||||
$tree = MenuTree::build([self::item(30, 31, 'A'), self::item(31, 30, 'B')]);
|
||||
|
||||
self::assertSame(['A', 'B'], array_column($tree, 'title'));
|
||||
self::assertSame([], $tree[0]['children']);
|
||||
self::assertSame([], $tree[1]['children']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user