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
126 lines
4.6 KiB
PHP
126 lines
4.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\WordPress\Menus;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\ChangeLog\ChangeLog;
|
|
use LIT\MCP\Integrations\WordPress\Menus\MenuAssignLocationAbility;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use Mockery;
|
|
|
|
final class MenuAssignLocationAbilityTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
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) => match ($id) {
|
|
8 => (object) ['term_id' => 8, 'name' => 'Neu'],
|
|
3 => (object) ['term_id' => 3, 'name' => 'Hauptmenü'],
|
|
default => false,
|
|
}
|
|
);
|
|
}
|
|
|
|
public function testAssignsAndReportsThePreviousMenu(): void
|
|
{
|
|
Functions\expect('set_theme_mod')->once()->with('nav_menu_locations', ['primary-menu' => 8]);
|
|
$log = Mockery::mock(ChangeLog::class);
|
|
$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 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);
|
|
$log->expects('record')
|
|
->with(
|
|
'lit/menu-assign-location',
|
|
'menu_location',
|
|
'primary-menu',
|
|
'Menü "Hauptmenü" (ID 3) von der Position primary-menu entfernt'
|
|
)
|
|
->andReturn(7);
|
|
|
|
$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();
|
|
|
|
$result = (new MenuAssignLocationAbility(Mockery::mock(ChangeLog::class)))
|
|
->execute(['location' => 'primary-menu', 'menu_id' => 99]);
|
|
|
|
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());
|
|
}
|
|
}
|