feat: deferred 1a items - menu_rev lock, lit_mcp_guides filter, warnings, schedule guard precision

Task 14 (rulings P17/P18, Q10):
- lit/menu-get returns menu_rev (Rev::ofMenu over id, parent, position,
  title, url, object, object_id); lit/menu-set-items requires it, refuses
  a stale one with rev_mismatch (hint: lit/menu-get) and returns the new
  menu_rev. Errors::revMismatch takes an optional message/hint.
- GuideRepository: filter lit_mcp_guides adds/overrides topics; invalid
  topic names and non-string content are ignored, files stay the default.
- lit/post-trash names front page, posts page and linking menus in the
  confirmation and as warnings; lit/menu-assign-location needs confirm
  to remove an assigned menu and names it; lit/post-schedule warns that
  a private entry becomes public; Divi hints no longer point to
  non-existing lit-divi-* tools.
- PostGuard::missedSchedule: 60 s publish window, zero GMT date falls
  back to get_gmt_from_date(post_date); post-schedule refuses dates
  within that window.
- write_failed after a clean rollback that keeps a revision/backup says
  "Die Aenderung wurde nicht gespeichert (... bleibt erhalten)" via the
  new state parameter (Errors::writeFailed / WriteFailed rolledBackState).
- wp-basis-smoke: menu_rev flow, unassign confirm, trash/menu and
  private-schedule warnings.

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 04:33:15 +02:00
co-authored by Claude Opus 5.5
parent 7035448f7d
commit 251934ce53
32 changed files with 700 additions and 98 deletions
@@ -18,7 +18,11 @@ final class MenuAssignLocationAbilityTest extends TestCase
Functions\when('get_registered_nav_menus')->justReturn(['primary-menu' => 'Hauptmenü']);
Functions\when('get_nav_menu_locations')->justReturn(['primary-menu' => 3]);
Functions\when('wp_get_nav_menu_object')->alias(
static fn (int $id) => $id === 8 ? (object) ['term_id' => 8, 'name' => 'Neu'] : false
static fn (int $id) => match ($id) {
8 => (object) ['term_id' => 8, 'name' => 'Neu'],
3 => (object) ['term_id' => 3, 'name' => 'Hauptmenü'],
default => false,
}
);
}
@@ -42,7 +46,21 @@ final class MenuAssignLocationAbilityTest extends TestCase
self::assertSame(6, $result['log_id']);
}
public function testZeroRemovesTheAssignment(): void
public function testRemovingAnAssignmentNeedsConfirmation(): void
{
Functions\expect('set_theme_mod')->never();
$result = (new MenuAssignLocationAbility(Mockery::mock(ChangeLog::class)))
->execute(['location' => 'primary-menu', 'menu_id' => 0]);
self::assertSame('lit_confirm_required', $result->get_error_code());
self::assertStringContainsString(
'"Hauptmenü" (ID 3)',
json_decode($result->get_error_message(), true)['message']
);
}
public function testZeroRemovesTheAssignmentAndNamesTheRemovedMenu(): void
{
Functions\expect('set_theme_mod')->once()->with('nav_menu_locations', []);
$log = Mockery::mock(ChangeLog::class);
@@ -51,16 +69,40 @@ final class MenuAssignLocationAbilityTest extends TestCase
'lit/menu-assign-location',
'menu_location',
'primary-menu',
'Zuweisung der Position primary-menu entfernt'
'Menü "Hauptmenü" (ID 3) von der Position primary-menu entfernt'
)
->andReturn(7);
$result = (new MenuAssignLocationAbility($log))->execute(['location' => 'primary-menu', 'menu_id' => 0]);
$result = (new MenuAssignLocationAbility($log))
->execute(['location' => 'primary-menu', 'menu_id' => 0, 'confirm' => true]);
self::assertSame('unassigned', $result['changed'][0]['action']);
self::assertSame(3, $result['previous_menu_id']);
self::assertStringContainsString('"Hauptmenü" (ID 3)', $result['summary']);
self::assertSame(7, $result['log_id']);
}
public function testRemovingFromAnEmptyLocationNeedsNoConfirmation(): void
{
Functions\when('get_nav_menu_locations')->justReturn([]);
Functions\expect('set_theme_mod')->once()->with('nav_menu_locations', []);
$log = Mockery::mock(ChangeLog::class);
$log->allows('record')->andReturn(8);
$result = (new MenuAssignLocationAbility($log))->execute(['location' => 'primary-menu', 'menu_id' => 0]);
self::assertTrue($result['ok']);
self::assertNull($result['previous_menu_id']);
}
public function testDescribesTheConfirmationForRemoval(): void
{
$ability = new MenuAssignLocationAbility(Mockery::mock(ChangeLog::class));
self::assertArrayHasKey('confirm', $ability->inputSchema()['properties']);
self::assertStringContainsString('confirm: true', $ability->description());
}
public function testUnknownMenuIsNotFound(): void
{
Functions\expect('set_theme_mod')->never();