Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
82 lines
2.9 KiB
PHP
82 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Core;
|
|
|
|
use Brain\Monkey\Filters;
|
|
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']);
|
|
}
|
|
|
|
public function testAllTopicsInOneCallOverviewFirst(): void
|
|
{
|
|
$result = $this->ability->execute(['topic' => 'all']);
|
|
|
|
self::assertSame('all', $result['topic']);
|
|
self::assertSame(['divi-shortform', 'overview'], $result['topics']);
|
|
$overview = strpos($result['content'], 'Thema `overview`');
|
|
$shortform = strpos($result['content'], 'Thema `divi-shortform`');
|
|
self::assertIsInt($overview);
|
|
self::assertIsInt($shortform);
|
|
self::assertLessThan($shortform, $overview);
|
|
self::assertStringNotContainsString('Nicht enthalten', $result['content']);
|
|
}
|
|
|
|
public function testAllTopicsStopAtTheSizeLimitAndNameTheRest(): void
|
|
{
|
|
$big = str_repeat('x', GuideAbility::ALL_LIMIT);
|
|
// Brain Monkey owns apply_filters(): answer the guide filter through its hooks API.
|
|
Filters\expectApplied('lit_mcp_guides')->andReturn(['gross' => $big]);
|
|
$ability = new GuideAbility(new GuideRepository(dirname(__DIR__, 3) . '/Fixtures/guides'));
|
|
|
|
$content = $ability->execute(['topic' => 'all'])['content'];
|
|
|
|
self::assertLessThanOrEqual(GuideAbility::ALL_LIMIT + 200, strlen($content));
|
|
self::assertStringContainsString('Nicht enthalten (Größenlimit): gross', $content);
|
|
}
|
|
}
|