Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
58 lines
2.0 KiB
PHP
58 lines
2.0 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) => $id === 8 ? (object) ['term_id' => 8, 'name' => 'Neu'] : 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')->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']);
|
|
}
|
|
|
|
public function testZeroRemovesTheAssignment(): void
|
|
{
|
|
Functions\expect('set_theme_mod')->once()->with('nav_menu_locations', []);
|
|
$log = Mockery::mock(ChangeLog::class);
|
|
$log->expects('record')->andReturn(7);
|
|
|
|
$result = (new MenuAssignLocationAbility($log))->execute(['location' => 'primary-menu', 'menu_id' => 0]);
|
|
|
|
self::assertSame('unassigned', $result['changed'][0]['action']);
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|