feat: content-types tool and WordPress integration
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\WordPress\Content;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Integrations\WordPress\Content\ContentTypesAbility;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use Mockery;
|
||||
use WP_Error;
|
||||
|
||||
final class ContentTypesAbilityTest extends TestCase
|
||||
{
|
||||
public function testListsAllTypesWithoutFields(): void
|
||||
{
|
||||
$schema = Mockery::mock(ContentSchema::class);
|
||||
$schema->expects('describePostTypes')->andReturn([['name' => 'page'], ['name' => 'post']]);
|
||||
|
||||
$result = (new ContentTypesAbility($schema))->execute([]);
|
||||
|
||||
self::assertSame(['post_types' => [['name' => 'page'], ['name' => 'post']]], $result);
|
||||
}
|
||||
|
||||
public function testSingleTypeIncludesFields(): void
|
||||
{
|
||||
$schema = Mockery::mock(ContentSchema::class);
|
||||
$schema->expects('describe')->with('lit_person', true)->andReturn(['name' => 'lit_person', 'fields' => []]);
|
||||
|
||||
$result = (new ContentTypesAbility($schema))->execute(['post_type' => 'lit_person']);
|
||||
|
||||
self::assertSame([['name' => 'lit_person', 'fields' => []]], $result['post_types']);
|
||||
}
|
||||
|
||||
public function testUnknownTypeIsNotFoundWithTheAvailableTypes(): void
|
||||
{
|
||||
$schema = Mockery::mock(ContentSchema::class);
|
||||
$schema->allows('describe')->andReturn(null);
|
||||
$schema->allows('postTypeNames')->andReturn(['page', 'post']);
|
||||
|
||||
$result = (new ContentTypesAbility($schema))->execute(['post_type' => 'nope']);
|
||||
|
||||
self::assertInstanceOf(WP_Error::class, $result);
|
||||
self::assertSame('lit_not_found', $result->get_error_code());
|
||||
self::assertStringContainsString('page, post', $result->get_error_message());
|
||||
}
|
||||
|
||||
public function testPermissionRequiresEditPosts(): void
|
||||
{
|
||||
Functions\when('current_user_can')->justReturn(false);
|
||||
$ability = new ContentTypesAbility(Mockery::mock(ContentSchema::class));
|
||||
|
||||
self::assertSame('lit_forbidden', $ability->permission([])->get_error_code());
|
||||
}
|
||||
|
||||
public function testMetadata(): void
|
||||
{
|
||||
$ability = new ContentTypesAbility(Mockery::mock(ContentSchema::class));
|
||||
|
||||
self::assertSame('lit/content-types', $ability->name());
|
||||
self::assertTrue($ability->isDirect());
|
||||
self::assertSame(['readonly' => true, 'destructive' => false, 'idempotent' => true], $ability->annotations());
|
||||
self::assertFalse($ability->inputSchema()['additionalProperties']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user