- search_inventory: global search across all 6 entity types - get_entity_history + get_activity_log: audit trail access - 4 comment tools: list, create, resolve, unresolved count - 3 custom field tools: list values, upsert, delete - 2 document tools: list, delete (upload via REST only) - 6 model type tools: list, get, create, update, delete, sync - 69 MCP tests pass total Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
99 lines
3.2 KiB
PHP
99 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Mcp\Tool\Comment;
|
|
|
|
use App\Entity\Comment;
|
|
use App\Tests\AbstractApiTestCase;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
class CommentsToolTest extends AbstractApiTestCase
|
|
{
|
|
public function testListComments(): void
|
|
{
|
|
$entityId = 'entity-'.uniqid();
|
|
$this->createComment('First comment', 'machine', $entityId);
|
|
$this->createComment('Second comment', 'machine', $entityId);
|
|
$this->createComment('Other entity', 'machine', 'other-id');
|
|
|
|
$session = $this->createMcpClient('ROLE_VIEWER');
|
|
|
|
$data = $this->callMcpTool($session, 'list_comments', [
|
|
'entityType' => 'machine',
|
|
'entityId' => $entityId,
|
|
]);
|
|
|
|
$this->assertArrayHasKey('_parsed', $data);
|
|
$this->assertSame(2, $data['_parsed']['total']);
|
|
$this->assertCount(2, $data['_parsed']['items']);
|
|
}
|
|
|
|
public function testCreateComment(): void
|
|
{
|
|
$session = $this->createMcpClient('ROLE_VIEWER');
|
|
|
|
$data = $this->callMcpTool($session, 'create_comment', [
|
|
'content' => 'A new comment',
|
|
'entityType' => 'machine',
|
|
'entityId' => 'some-machine-id',
|
|
'entityName' => 'Machine Alpha',
|
|
]);
|
|
|
|
$this->assertArrayHasKey('_parsed', $data);
|
|
$this->assertNotEmpty($data['_parsed']['id']);
|
|
$this->assertSame('A new comment', $data['_parsed']['content']);
|
|
$this->assertSame('machine', $data['_parsed']['entityType']);
|
|
$this->assertSame('open', $data['_parsed']['status']);
|
|
$this->assertSame('Machine Alpha', $data['_parsed']['entityName']);
|
|
}
|
|
|
|
public function testResolveComment(): void
|
|
{
|
|
$comment = $this->createComment('To resolve', 'piece', 'piece-123');
|
|
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
|
|
|
$data = $this->callMcpTool($session, 'resolve_comment', [
|
|
'commentId' => $comment->getId(),
|
|
]);
|
|
|
|
$this->assertArrayHasKey('_parsed', $data);
|
|
$this->assertSame('resolved', $data['_parsed']['status']);
|
|
$this->assertNotEmpty($data['_parsed']['resolvedByName']);
|
|
}
|
|
|
|
public function testUnresolvedCount(): void
|
|
{
|
|
$entityId = 'entity-'.uniqid();
|
|
$this->createComment('Open 1', 'machine', $entityId, 'open');
|
|
$this->createComment('Open 2', 'machine', $entityId, 'open');
|
|
$this->createComment('Resolved', 'machine', $entityId, 'resolved');
|
|
|
|
$session = $this->createMcpClient('ROLE_VIEWER');
|
|
|
|
$data = $this->callMcpTool($session, 'get_unresolved_comments_count');
|
|
|
|
$this->assertArrayHasKey('_parsed', $data);
|
|
$this->assertGreaterThanOrEqual(2, $data['_parsed']['count']);
|
|
}
|
|
|
|
private function createComment(string $content, string $entityType, string $entityId, string $status = 'open'): Comment
|
|
{
|
|
$comment = new Comment();
|
|
$comment->setContent($content);
|
|
$comment->setEntityType($entityType);
|
|
$comment->setEntityId($entityId);
|
|
$comment->setAuthorId('test-author-id');
|
|
$comment->setAuthorName('Test Author');
|
|
$comment->setStatus($status);
|
|
|
|
$em = $this->getEntityManager();
|
|
$em->persist($comment);
|
|
$em->flush();
|
|
|
|
return $comment;
|
|
}
|
|
}
|