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
65 lines
2.3 KiB
PHP
65 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Limits;
|
|
|
|
final class LimitsTest extends TestCase
|
|
{
|
|
public function testDefaultsWhenOptionIsMissing(): void
|
|
{
|
|
Functions\when('get_option')->justReturn([]);
|
|
$limits = new Limits();
|
|
|
|
self::assertSame(5 * 1024 * 1024, $limits->uploadBytes());
|
|
self::assertSame(5, $limits->uploadMegabytes());
|
|
self::assertSame(90, $limits->logRetentionDays());
|
|
self::assertSame(20, $limits->snapshotCount());
|
|
}
|
|
|
|
public function testStoredValuesAreClamped(): void
|
|
{
|
|
Functions\when('get_option')->justReturn(['upload_mb' => 500, 'log_retention_days' => 0, 'snapshot_count' => '7']);
|
|
|
|
self::assertSame(['upload_mb' => 100, 'log_retention_days' => 1, 'snapshot_count' => 7], (new Limits())->all());
|
|
}
|
|
|
|
public function testCorruptOptionFallsBackToDefaults(): void
|
|
{
|
|
Functions\when('get_option')->justReturn('garbage');
|
|
|
|
self::assertSame(Limits::DEFAULTS, (new Limits())->all());
|
|
}
|
|
|
|
public function testSanitizeReturnsACompleteClampedArray(): void
|
|
{
|
|
self::assertSame(
|
|
['upload_mb' => 12, 'log_retention_days' => 90, 'snapshot_count' => 100],
|
|
Limits::sanitize(['upload_mb' => '12', 'log_retention_days' => 'x', 'snapshot_count' => 1000])
|
|
);
|
|
self::assertSame(Limits::DEFAULTS, Limits::sanitize(null));
|
|
}
|
|
|
|
public function testBoundsMatchesWhatSanitizeClampsTo(): void
|
|
{
|
|
self::assertSame([1, 100], Limits::bounds()['upload_mb']);
|
|
self::assertSame([1, 3650], Limits::bounds()['log_retention_days']);
|
|
self::assertSame([1, 100], Limits::bounds()['snapshot_count']);
|
|
|
|
// Cross-check against sanitize()'s actual clamping, so the two can't drift apart.
|
|
$tooLow = array_map(static fn (array $bound): int => $bound[0] - 1, Limits::bounds());
|
|
$tooHigh = array_map(static fn (array $bound): int => $bound[1] + 1, Limits::bounds());
|
|
self::assertSame(
|
|
array_map(static fn (array $bound): int => $bound[0], Limits::bounds()),
|
|
Limits::sanitize($tooLow)
|
|
);
|
|
self::assertSame(
|
|
array_map(static fn (array $bound): int => $bound[1], Limits::bounds()),
|
|
Limits::sanitize($tooHigh)
|
|
);
|
|
}
|
|
}
|