feat: tools and limits settings tabs
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
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Admin;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Admin\LimitsTab;
|
||||
use LIT\MCP\Limits;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use Mockery;
|
||||
|
||||
final class LimitsTabTest extends TestCase
|
||||
{
|
||||
public function testRegistersTheLimitsOption(): void
|
||||
{
|
||||
Functions\expect('register_setting')->once()->with(
|
||||
'lit_mcp_limits',
|
||||
'lit_mcp_limits',
|
||||
Mockery::on(static fn (array $args): bool => $args['sanitize_callback'] === [Limits::class, 'sanitize']
|
||||
&& $args['default'] === Limits::DEFAULTS)
|
||||
);
|
||||
|
||||
(new LimitsTab())->registerSettings();
|
||||
}
|
||||
|
||||
public function testRendersThreeNumberFieldsWithCurrentValues(): void
|
||||
{
|
||||
Functions\stubEscapeFunctions();
|
||||
Functions\stubTranslationFunctions();
|
||||
Functions\when('settings_fields')->justReturn(null);
|
||||
Functions\when('submit_button')->justReturn(null);
|
||||
Functions\when('get_option')->justReturn(['upload_mb' => 8]);
|
||||
|
||||
ob_start();
|
||||
(new LimitsTab())->render();
|
||||
$html = (string) ob_get_clean();
|
||||
|
||||
self::assertSame(3, substr_count($html, 'type="number"'));
|
||||
self::assertStringContainsString('name="lit_mcp_limits[upload_mb]" value="8"', $html);
|
||||
self::assertStringContainsString('name="lit_mcp_limits[log_retention_days]" value="90"', $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user