Files
WP-LIT-MCP/tests/Unit/Abilities/RevAndJsonMapTest.php
T
janniclas.loosenandClaude Opus 5.5 4f9a47fe32 feat: content-create and content-update with schema validation
All-or-nothing writes: validation (fields, terms, featured image, parent,
template) before any write; failed extras delete the new draft (create) or
restore revision, old columns, fields, terms and featured image (update).
content-update requires rev; Rev::ofPost covers content, title, excerpt,
status and post_modified_gmt. MetaFieldSource::write() now throws on failure.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
2026-09-25 23:01:48 +02:00

49 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Abilities;
use LIT\MCP\Abilities\JsonMap;
use LIT\MCP\Abilities\Rev;
use LIT\MCP\Tests\Unit\TestCase;
use stdClass;
use WP_Post;
final class RevAndJsonMapTest extends TestCase
{
public function testRevIsShortDeterministicAndContentSensitive(): void
{
self::assertMatchesRegularExpression('/^[0-9a-f]{12}$/', Rev::of('abc'));
self::assertSame(Rev::of('abc'), Rev::of('abc'));
self::assertNotSame(Rev::of('abc'), Rev::of('abd'));
}
public function testPostRevCoversContentTitleExcerptStatusAndModification(): void
{
$base = [
'post_content' => '<p>A</p>',
'post_title' => 'T',
'post_excerpt' => 'E',
'post_status' => 'draft',
'post_modified_gmt' => '2026-09-25 08:00:00',
];
$rev = Rev::ofPost(new WP_Post($base));
self::assertMatchesRegularExpression('/^[0-9a-f]{12}$/', $rev);
self::assertSame($rev, Rev::ofPost(new WP_Post($base)));
self::assertNotSame(Rev::of('<p>A</p>'), $rev);
foreach (['post_content' => '<p>B</p>', 'post_title' => 'U', 'post_excerpt' => 'F',
'post_status' => 'publish', 'post_modified_gmt' => '2026-09-25 08:00:01'] as $key => $value) {
self::assertNotSame($rev, Rev::ofPost(new WP_Post(array_merge($base, [$key => $value]))), $key);
}
}
public function testEmptyMapBecomesJsonObject(): void
{
self::assertInstanceOf(stdClass::class, JsonMap::of([]));
self::assertSame('{}', json_encode(JsonMap::of([])));
self::assertSame(['a' => 1], JsonMap::of(['a' => 1]));
}
}