Fix round 1 (task 10 review): - FieldValidator's "unknown field" validation error (reaches the client via validation_failed's fields) and PostPresenter's DIVI_HINT (surfaced in the result's hints array) still named lit-content-types/lit-content-update as plain lit-<name>; converted both to the neutral "lit/<name> (direkt: lit-<name>)" form like the other hints from task 10. Re-grepped src/ for any other client-facing error/field/hints text naming a direct-by-default tool as lit-<name> (descriptions/schemas excluded per Q11c) - none left. - Added Limits::bounds() (field => [min, max]) and made LimitsTab use it for the number inputs' min/max instead of a second, hardcoded copy of the same bounds. - LimitsTab now shows a description note when the configured upload_mb exceeds wp_max_upload_size() (PHP's upload_max_filesize/post_max_size), since WordPress would refuse a larger upload before this limit ever applies. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
80 lines
2.9 KiB
PHP
80 lines
2.9 KiB
PHP
<?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]);
|
|
Functions\when('wp_max_upload_size')->justReturn(64 * 1024 * 1024);
|
|
|
|
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);
|
|
self::assertStringContainsString('min="1" max="100"', $html);
|
|
self::assertStringContainsString('min="1" max="3650"', $html);
|
|
}
|
|
|
|
public function testWarnsWhenUploadMbExceedsTheServersOwnUploadLimit(): void
|
|
{
|
|
Functions\stubEscapeFunctions();
|
|
Functions\stubTranslationFunctions();
|
|
Functions\when('settings_fields')->justReturn(null);
|
|
Functions\when('submit_button')->justReturn(null);
|
|
Functions\when('get_option')->justReturn(['upload_mb' => 50]);
|
|
Functions\when('wp_max_upload_size')->justReturn(2 * 1024 * 1024);
|
|
|
|
ob_start();
|
|
(new LimitsTab())->render();
|
|
$html = (string) ob_get_clean();
|
|
|
|
self::assertStringContainsString('class="description"', $html);
|
|
self::assertMatchesRegularExpression('/50 MB.*2 MB/s', $html);
|
|
}
|
|
|
|
public function testNoWarningWhenUploadMbIsWithinTheServersOwnUploadLimit(): void
|
|
{
|
|
Functions\stubEscapeFunctions();
|
|
Functions\stubTranslationFunctions();
|
|
Functions\when('settings_fields')->justReturn(null);
|
|
Functions\when('submit_button')->justReturn(null);
|
|
Functions\when('get_option')->justReturn(['upload_mb' => 5]);
|
|
Functions\when('wp_max_upload_size')->justReturn(64 * 1024 * 1024);
|
|
|
|
ob_start();
|
|
(new LimitsTab())->render();
|
|
$html = (string) ob_get_clean();
|
|
|
|
self::assertStringNotContainsString('class="description"', $html);
|
|
}
|
|
}
|