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
65 lines
2.5 KiB
PHP
65 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\WordPress\Menus;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Abilities\Rev;
|
|
use LIT\MCP\Integrations\WordPress\Menus\MenuGetAbility;
|
|
use LIT\MCP\Integrations\WordPress\Menus\MenuListAbility;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
|
|
final class MenuReadAbilitiesTest extends TestCase
|
|
{
|
|
use MenuFixtures;
|
|
|
|
public function testListShowsMenusAndLocations(): void
|
|
{
|
|
Functions\when('wp_get_nav_menus')->justReturn([
|
|
(object) ['term_id' => 3, 'name' => 'Hauptmenü', 'slug' => 'hauptmenue', 'count' => 4],
|
|
]);
|
|
Functions\when('get_registered_nav_menus')->justReturn(
|
|
['primary-menu' => 'Hauptmenü', 'footer-menu' => 'Footer']
|
|
);
|
|
Functions\when('get_nav_menu_locations')->justReturn(['primary-menu' => 3]);
|
|
|
|
$result = (new MenuListAbility())->execute([]);
|
|
|
|
self::assertSame(['primary-menu'], $result['menus'][0]['locations']);
|
|
self::assertSame(
|
|
[
|
|
['location' => 'primary-menu', 'description' => 'Hauptmenü', 'menu_id' => 3],
|
|
['location' => 'footer-menu', 'description' => 'Footer', 'menu_id' => null],
|
|
],
|
|
$result['locations']
|
|
);
|
|
}
|
|
|
|
public function testGetReturnsTheTreeOrNotFound(): void
|
|
{
|
|
Functions\when('wp_get_nav_menu_object')->alias(
|
|
static fn (int $id) => $id === 3 ? (object) ['term_id' => 3, 'name' => 'Hauptmenü'] : false
|
|
);
|
|
Functions\when('wp_get_nav_menu_items')->justReturn([self::item(10, 0, 'Start')]);
|
|
Functions\when('get_nav_menu_locations')->justReturn([]);
|
|
$ability = new MenuGetAbility();
|
|
|
|
$result = $ability->execute(['menu_id' => 3]);
|
|
|
|
self::assertSame('Hauptmenü', $result['name']);
|
|
self::assertSame('Start', $result['items'][0]['title']);
|
|
self::assertSame(Rev::ofMenu([self::item(10, 0, 'Start')]), $result['menu_rev']);
|
|
self::assertContains('menu_rev', $ability->outputSchema()['required']);
|
|
self::assertSame('lit_not_found', $ability->execute(['menu_id' => 9])->get_error_code());
|
|
}
|
|
|
|
public function testReadToolsNeedThemeOptionRights(): void
|
|
{
|
|
Functions\when('current_user_can')->justReturn(false);
|
|
|
|
self::assertSame('lit_forbidden', (new MenuListAbility())->permission([])->get_error_code());
|
|
self::assertSame('lit_forbidden', (new MenuGetAbility())->permission(['menu_id' => 3])->get_error_code());
|
|
}
|
|
}
|