Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use InvalidArgumentException;
|
|
use LIT\MCP\Integrations\Divi\Design\PageRewriter;
|
|
use LIT\MCP\Integrations\Divi\Design\PostIdsInput;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class PostIdsInputTest extends TestCase
|
|
{
|
|
public function testParsesAListOfPositiveIdsWithoutDuplicates(): void
|
|
{
|
|
self::assertNull(PostIdsInput::parse(null));
|
|
self::assertSame([12, 13], PostIdsInput::parse([12, 13, 12]));
|
|
self::assertSame(PageRewriter::PAGE_LIMIT, PostIdsInput::MAX);
|
|
}
|
|
|
|
/** @dataProvider invalidInput */
|
|
public function testRefusesEverythingElse(mixed $value): void
|
|
{
|
|
$this->expectException(InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Liste von 1 bis 50 Beitrags-IDs (positive ganze Zahlen) erwartet');
|
|
|
|
PostIdsInput::parse($value);
|
|
}
|
|
|
|
/** @return array<string, array{mixed}> */
|
|
public static function invalidInput(): array
|
|
{
|
|
return [
|
|
'leer' => [[]],
|
|
'null als ID' => [[0]],
|
|
'negativ' => [[-3]],
|
|
'Text' => [['12']],
|
|
'Objekt' => [['a' => 1]],
|
|
'zu viele' => [range(1, 51)],
|
|
'keine Liste' => [12],
|
|
];
|
|
}
|
|
|
|
public function testSchemaMatchesTheParser(): void
|
|
{
|
|
$schema = PostIdsInput::schema();
|
|
|
|
self::assertSame('array', $schema['type']);
|
|
self::assertSame(1, $schema['minItems']);
|
|
self::assertSame(50, $schema['maxItems']);
|
|
self::assertSame(['type' => 'integer', 'minimum' => 1], $schema['items']);
|
|
}
|
|
}
|