justReturn(false); Functions\when('rest_url')->justReturn('https://kunde.de/wp-json/mcp/mcp-oauth-server'); Functions\expect('wp_remote_post')->once()->with('https://kunde.de/wp-json/mcp/mcp-oauth-server', Mockery::type('array')) ->andReturn(['response' => ['code' => 401]]); Functions\when('wp_remote_retrieve_response_code')->justReturn(401); Functions\when('wp_remote_retrieve_header')->justReturn('Bearer realm="https://kunde.de"'); Functions\expect('set_transient')->once() ->with('lit_mcp_endpoint_check', Mockery::on(static fn (array $value): bool => $value['ok'] === true), 300); $result = (new ConnectionStatus(static fn (): bool => true))->endpoint(true); self::assertTrue($result['ok']); } public function testEndpointAnsweringWithoutChallengeIsReported(): void { Functions\when('get_transient')->justReturn(false); Functions\when('rest_url')->justReturn('https://kunde.de/wp-json/mcp/mcp-oauth-server'); Functions\when('wp_remote_post')->justReturn(['response' => ['code' => 200]]); Functions\when('wp_remote_retrieve_response_code')->justReturn(200); Functions\when('wp_remote_retrieve_header')->justReturn(''); Functions\when('set_transient')->justReturn(true); $result = (new ConnectionStatus(static fn (): bool => true))->endpoint(true); self::assertFalse($result['ok']); self::assertStringContainsString('200', $result['message']); } public function testChecksWithoutFetchingUseOnlyCachedResults(): void { Functions\when('get_transient')->justReturn(false); Functions\expect('wp_remote_post')->never(); Functions\when('home_url')->justReturn('http://kunde.test'); $checks = (new ConnectionStatus(static fn (): bool => false))->checks(false); $byLabel = array_column($checks, null, 'label'); self::assertFalse($byLabel['OAuth-Server']['ok']); self::assertFalse($byLabel['HTTPS']['ok']); self::assertNull($byLabel['OAuth-Discovery']['ok']); self::assertNull($byLabel['MCP-Endpunkt']['ok']); } public function testDiscoveryDetailIsGermanInsteadOfTheLibrarysEnglishLabel(): void { Functions\when('get_transient')->alias(static fn (string $key) => $key === 'lit_mcp_endpoint_check' ? false : ['label' => 'MCP OAuth discovery documents', 'status' => 'good']); Functions\when('home_url')->justReturn('https://kunde.test'); $good = array_column((new ConnectionStatus(static fn (): bool => true))->checks(false), null, 'label'); self::assertTrue($good['OAuth-Discovery']['ok']); self::assertSame('Discovery-Dokumente erreichbar', $good['OAuth-Discovery']['message']); Functions\when('get_transient')->alias(static fn (string $key) => $key === 'lit_mcp_endpoint_check' ? false : ['label' => 'MCP OAuth discovery documents', 'status' => 'critical']); $bad = array_column((new ConnectionStatus(static fn (): bool => true))->checks(false), null, 'label'); self::assertFalse($bad['OAuth-Discovery']['ok']); self::assertStringContainsString('nicht erreichbar', $bad['OAuth-Discovery']['message']); self::assertStringNotContainsString('documents', $bad['OAuth-Discovery']['message']); } public function testPermalinksPrettyReflectsThePermalinkStructureOption(): void { Functions\when('get_option')->justReturn('/%postname%/'); self::assertTrue((new ConnectionStatus())->permalinksPretty()); Functions\when('get_option')->justReturn(''); self::assertFalse((new ConnectionStatus())->permalinksPretty()); } }