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:
2026-09-26 00:07:44 +02:00
co-authored by Claude Opus 5.5
parent 1d59d1d2ad
commit 954f683dd2
4 changed files with 95 additions and 7 deletions
@@ -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());
}
}