tests/Support/AssertsToolErrors (used by TestCase): assertToolError($result, code)
checks the WP_Error code lit_<code> and the code of the client JSON and returns the
payload; clientError() decodes the payload; errorFields() returns the fields and
asserts they exist. Replaces the private clientError() decoders of
DiviWriteAbilitiesTest/DiviReplaceTextAbilityTest, 216 single-line
assertSame('lit_…', …->get_error_code()) assertions, 24 get_error_data()['fields']
digs and two json_decode(message) reads. ErrorsTest keeps json_decode: it tests
the format itself. Tests 1404 -> 1409 (AssertsToolErrorsTest); no test has fewer
assertions.
Co-Authored-By: Claude Opus 5.5 (1M context) <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\Core;
|
|
|
|
use LIT\MCP\Guides\GuideRepository;
|
|
use LIT\MCP\Integrations\Core\GuideAbility;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use WP_Error;
|
|
|
|
final class GuideAbilityTest extends TestCase
|
|
{
|
|
private GuideAbility $ability;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->ability = new GuideAbility(new GuideRepository(dirname(__DIR__, 3) . '/Fixtures/guides'));
|
|
}
|
|
|
|
public function testWithoutTopicReturnsOverviewAndTopicList(): void
|
|
{
|
|
$result = $this->ability->execute([]);
|
|
|
|
self::assertSame('overview', $result['topic']);
|
|
self::assertSame(['divi-shortform', 'overview'], $result['topics']);
|
|
self::assertStringContainsString('Testinhalt Übersicht', $result['content']);
|
|
}
|
|
|
|
public function testReturnsRequestedTopic(): void
|
|
{
|
|
$result = $this->ability->execute(['topic' => 'divi-shortform']);
|
|
|
|
self::assertStringContainsString('Testinhalt Kurzform', $result['content']);
|
|
}
|
|
|
|
public function testUnknownTopicIsNotFoundErrorListingTopics(): void
|
|
{
|
|
$result = $this->ability->execute(['topic' => '../../wp-config']);
|
|
|
|
self::assertInstanceOf(WP_Error::class, $result);
|
|
self::assertToolError($result, 'not_found');
|
|
self::assertStringContainsString('divi-shortform', $result->get_error_message());
|
|
}
|
|
|
|
public function testIsDirectReadOnlyTool(): void
|
|
{
|
|
self::assertSame('lit/guide', $this->ability->name());
|
|
self::assertTrue($this->ability->isDirect());
|
|
self::assertTrue($this->ability->annotations()['readonly']);
|
|
}
|
|
}
|