Files
WP-LIT-MCP/tests/Unit/Abilities/CursorTest.php
T
janniclas.loosenandClaude Opus 5.5 60290c85a5 test: AssertsToolErrors helper for tool error assertions (T3)
tests/Support/AssertsToolErrors (used by TestCase): assertToolError($result, code)
checks the WP_Error code lit_<code> and the code of the client JSON and returns the
payload; clientError() decodes the payload; errorFields() returns the fields and
asserts they exist. Replaces the private clientError() decoders of
DiviWriteAbilitiesTest/DiviReplaceTextAbilityTest, 216 single-line
assertSame('lit_…', …->get_error_code()) assertions, 24 get_error_data()['fields']
digs and two json_decode(message) reads. ErrorsTest keeps json_decode: it tests
the format itself. Tests 1404 -> 1409 (AssertsToolErrorsTest); no test has fewer
assertions.

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

60 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Abilities;
use LIT\MCP\Abilities\Cursor;
use LIT\MCP\Tests\Unit\TestCase;
final class CursorTest extends TestCase
{
public function testRoundTrip(): void
{
self::assertSame(40, Cursor::decode(Cursor::encode(40)));
}
public function testMissingCursorStartsAtZero(): void
{
self::assertSame(0, Cursor::decode(null));
self::assertSame(0, Cursor::decode(''));
}
public function testTamperedCursorIsRejected(): void
{
self::assertNull(Cursor::decode('not-a-cursor'));
self::assertNull(Cursor::decode(base64_encode('o:-5')));
self::assertNull(Cursor::decode(base64_encode('o:12;DROP')));
}
public function testLimitIsClamped(): void
{
self::assertSame(20, Cursor::limit(null));
self::assertSame(1, Cursor::limit(0));
self::assertSame(100, Cursor::limit(500));
self::assertSame(7, Cursor::limit(7));
}
public function testPageDetectsMoreRows(): void
{
$page = Cursor::page([1, 2, 3], 2, 10);
self::assertSame([1, 2], $page['items']);
self::assertSame(12, Cursor::decode($page['next_cursor']));
self::assertNull(Cursor::page([1, 2], 2, 0)['next_cursor']);
}
public function testInvalidCursorErrorIsAValidationError(): void
{
self::assertToolError(Cursor::invalid(), 'validation_failed');
}
public function testInputPropertiesDescribeLimitAndCursor(): void
{
$properties = Cursor::inputProperties();
self::assertSame(100, $properties['limit']['maximum']);
self::assertSame('string', $properties['cursor']['type']);
}
}