Files
WP-LIT-MCP/tests/Unit/Admin/LimitsTabTest.php
T
janniclas.loosenandClaude Opus 5.5 843f45aeec feat: admin settings page UI/UX pass with WordPress-native patterns
- Header: h1 + logo in a wrapping flex row, hr.wp-header-end before the tabs,
  aria-current on the active tab; own CSS/JS enqueued only on this screen.
- Verbindung: ordered "So verbindest du Claude" steps, copy button (core
  clipboard.js + wp.a11y.speak), Site-Health-style status list, German details.
- Zugriff: roles as form-table fieldset, connections with site date format,
  empty-state row, confirm on revoke; ConnectionUsage records last use via
  WP_Application_Passwords::record_application_password_usage (once a day).
- Tools: plain-language legend, counter as inline notice, groups as core
  postboxes (postbox.js toggles, per-user closed state, summary when closed),
  fixed column widths with new "Art" column, submit above and below.
- Protokoll: site-timezone times with UTC tooltip, result icons, filters with
  labels in the list table nav, retention link to Limits.
- Limits: short labels with units and descriptions; snapshot count hidden but
  preserved.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 16:50:58 +02:00

93 lines
4.1 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 testRendersVisibleNumberFieldsWithShortLabelsUnitsAndDescriptions(): 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, 'snapshot_count' => 42]);
Functions\when('wp_max_upload_size')->justReturn(64 * 1024 * 1024);
ob_start();
(new LimitsTab())->render();
$html = (string) ob_get_clean();
self::assertSame(2, substr_count($html, 'type="number"'));
self::assertStringContainsString('<label for="lit-mcp-upload_mb">Maximale Dateigröße</label>', $html);
self::assertStringContainsString('<label for="lit-mcp-log_retention_days">Protokoll aufbewahren</label>', $html);
self::assertStringContainsString('class="small-text"', $html);
self::assertStringContainsString('<span class="lit-mcp-unit">MB</span>', $html);
self::assertStringContainsString('<span class="lit-mcp-unit">Tage</span>', $html);
self::assertStringContainsString('aria-describedby="lit-mcp-upload_mb-description"', $html);
self::assertStringContainsString('<p class="description" id="lit-mcp-upload_mb-description">Höchstens 32 MB; für Base64-Übertragungen höchstens 10 MB.</p>', $html);
// The snapshot setting is hidden until its feature exists, but its saved value survives a save.
self::assertStringNotContainsString('Designsystem', $html);
self::assertStringNotContainsString('Etappe', $html);
self::assertStringContainsString('<input type="hidden" name="lit_mcp_limits[snapshot_count]" value="42">', $html);
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="32"', $html);
self::assertStringContainsString('Höchstens 32', $html);
self::assertStringContainsString('10 MB', $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' => 20]);
Functions\when('wp_max_upload_size')->justReturn(2 * 1024 * 1024);
ob_start();
(new LimitsTab())->render();
$html = (string) ob_get_clean();
self::assertStringContainsString('notice-warning inline', $html);
self::assertMatchesRegularExpression('/20 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('notice-warning', $html);
}
}