Adds Einstellungen → LIT MCP → Tools (direct/indirect/disabled per ability, only ExposurePolicy-allowed modes offered) and → Limits (upload size, log retention, snapshot count), wired into Plugin.php. Ruling Q11b (carried from task 6): overview.md notes that direct visibility is configurable; hints in src/ that name a tool which is direct by default but can be switched to indirect (content-get, content-query, content-types, post-publish, media-search) now use the neutral "lit/<name> (direkt: lit-<name>)" form so they stay correct after an admin override. lit/guide (always direct) and the media-preview/-download DIRECT_ONLY tools are unaffected. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
68 lines
2.6 KiB
PHP
68 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Admin;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Abilities\Ability;
|
|
use LIT\MCP\Abilities\ExposurePolicy;
|
|
use LIT\MCP\Admin\ToolsTab;
|
|
use LIT\MCP\Integrations\Integration;
|
|
use LIT\MCP\Integrations\IntegrationRegistry;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use Mockery;
|
|
|
|
final class ToolsTabTest extends TestCase
|
|
{
|
|
private function registry(): IntegrationRegistry
|
|
{
|
|
$abilities = [];
|
|
foreach ([['lit/guide', true], ['lit/media-preview', true], ['lit/menu-list', false]] as [$name, $direct]) {
|
|
$ability = Mockery::mock(Ability::class);
|
|
$ability->allows('name')->andReturn($name);
|
|
$ability->allows('label')->andReturn('Label ' . $name);
|
|
$ability->allows('isDirect')->andReturn($direct);
|
|
$abilities[] = $ability;
|
|
}
|
|
$integration = Mockery::mock(Integration::class);
|
|
$integration->allows('isAvailable')->andReturn(true);
|
|
$integration->allows('abilities')->andReturn($abilities);
|
|
|
|
return new IntegrationRegistry($integration);
|
|
}
|
|
|
|
public function testRegistersTheExposureOptionWithThePolicySanitizer(): void
|
|
{
|
|
Functions\expect('register_setting')->once()->with(
|
|
'lit_mcp_tools',
|
|
'lit_mcp_exposure',
|
|
Mockery::on(static fn (array $args): bool => $args['sanitize_callback'] === [ExposurePolicy::class, 'sanitize'])
|
|
);
|
|
|
|
(new ToolsTab($this->registry(), new ExposurePolicy()))->registerSettings();
|
|
}
|
|
|
|
public function testRendersOneSelectPerAbilityWithOnlyAllowedModes(): void
|
|
{
|
|
Functions\stubEscapeFunctions();
|
|
Functions\stubTranslationFunctions();
|
|
Functions\when('settings_fields')->justReturn(null);
|
|
Functions\when('submit_button')->justReturn(null);
|
|
Functions\when('selected')->alias(static fn ($a, $b = true, $echo = true): string => (string) $a === (string) $b ? ' selected="selected"' : '');
|
|
|
|
ob_start();
|
|
(new ToolsTab($this->registry(), new ExposurePolicy(['lit/menu-list' => 'disabled'])))->render();
|
|
$html = (string) ob_get_clean();
|
|
|
|
$selects = array_slice(explode('<select', $html), 1);
|
|
self::assertCount(3, $selects);
|
|
[$guide, $preview, $menu] = $selects;
|
|
self::assertStringContainsString('lit_mcp_exposure[lit/guide]', $guide);
|
|
self::assertStringNotContainsString('value="disabled"', $guide);
|
|
self::assertStringNotContainsString('value="indirect"', $preview);
|
|
self::assertStringContainsString('value="disabled" selected="selected"', $menu);
|
|
self::assertStringContainsString('value="" selected="selected"', $guide);
|
|
}
|
|
}
|