- PostGuard::editable() refuses trashed entries unless the caller opts in (content-get, revisions-list, post-trash); publish/schedule/unpublish/update/ restore/duplicate/replace now refuse them. - PostGuard::statusStable(): content-update, revision-restore and replace-with-copy refuse a future post whose date has passed (any save would publish it); the content-update rollback and PostCloner row writes re-check. - PostCloner::ownMeta() treats a failed SELECT as an error; replace() reads the copy before its first write. - replace-with-copy needs create_posts (backup clone) and reports backup_id in write_failed/partial_write. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
62 lines
2.4 KiB
PHP
62 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\WordPress\Content;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Integrations\WordPress\Content\ContentGetAbility;
|
|
use LIT\MCP\Integrations\WordPress\Content\PostPresenter;
|
|
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use Mockery;
|
|
use WP_Post;
|
|
|
|
final class ContentGetAbilityTest extends TestCase
|
|
{
|
|
public function testReturnsThePresentedPost(): void
|
|
{
|
|
$post = new WP_Post(['ID' => 5, 'post_type' => 'page']);
|
|
Functions\when('get_post')->justReturn($post);
|
|
Functions\when('current_user_can')->justReturn(true);
|
|
$schema = Mockery::mock(ContentSchema::class);
|
|
$schema->allows('isManaged')->andReturn(true);
|
|
$presenter = Mockery::mock(PostPresenter::class);
|
|
$presenter->expects('full')->with($post)->andReturn(['id' => 5]);
|
|
$ability = new ContentGetAbility($schema, $presenter);
|
|
|
|
self::assertTrue($ability->permission(['post_id' => 5]));
|
|
self::assertSame(['id' => 5], $ability->execute(['post_id' => 5]));
|
|
}
|
|
|
|
public function testATrashedPostCanStillBeRead(): void
|
|
{
|
|
$post = new WP_Post(['ID' => 5, 'post_type' => 'page', 'post_status' => 'trash']);
|
|
Functions\when('get_post')->justReturn($post);
|
|
Functions\when('current_user_can')->justReturn(true);
|
|
$schema = Mockery::mock(ContentSchema::class);
|
|
$schema->allows('isManaged')->andReturn(true);
|
|
$presenter = Mockery::mock(PostPresenter::class);
|
|
$presenter->expects('full')->with($post)->andReturn(['id' => 5]);
|
|
|
|
self::assertSame(['id' => 5], (new ContentGetAbility($schema, $presenter))->execute(['post_id' => 5]));
|
|
}
|
|
|
|
public function testMissingPostIsNotFound(): void
|
|
{
|
|
Functions\when('get_post')->justReturn(null);
|
|
$schema = Mockery::mock(ContentSchema::class);
|
|
$ability = new ContentGetAbility($schema, Mockery::mock(PostPresenter::class));
|
|
|
|
self::assertSame('lit_not_found', $ability->permission(['post_id' => 99])->get_error_code());
|
|
}
|
|
|
|
public function testOutputSchemaAllowsNullContentForDivi(): void
|
|
{
|
|
$ability = new ContentGetAbility(Mockery::mock(ContentSchema::class), Mockery::mock(PostPresenter::class));
|
|
|
|
self::assertSame(['string', 'null'], $ability->outputSchema()['properties']['content']['type']);
|
|
self::assertTrue($ability->isDirect());
|
|
}
|
|
}
|