*/ private function realDiscoveryResult(string $status): array { return [ 'label' => 'MCP OAuth discovery documents', 'status' => $status, 'badge' => ['label' => 'Configuration', 'color' => 'blue'], 'description' => '
The following .well-known discovery document(s) did not respond as expected: ' . 'oauth-protected-resource.
', 'actions' => 'Check your error/access logs for the requests to these paths…
', 'test' => 'wpmedia_mcp_oauth_wellknown_discovery', ]; } private function status(bool $oauth, ?array $discovery, bool $https, bool $permalinksPretty = true): ConnectionStatus { $status = Mockery::mock(ConnectionStatus::class); $status->allows('oauthEnabled')->andReturn($oauth); $status->allows('discovery')->with(false)->andReturn($discovery); $status->allows('https')->andReturn($https); $status->allows('permalinksPretty')->andReturn($permalinksPretty); return $status; } public function testWarnsAboutDisabledOAuth(): void { $messages = (new AdminNotices($this->status(false, null, true)))->messages(false); self::assertCount(1, $messages); self::assertStringContainsString('OAuth-Server ist deaktiviert', $messages[0]); } public function testWarnsWhenTheCachedDiscoveryStatusIsCriticalOrRecommended(): void { foreach (['critical', 'recommended'] as $status) { $messages = (new AdminNotices($this->status(true, $this->realDiscoveryResult($status), true))) ->messages(false); self::assertCount(1, $messages, "status={$status}"); self::assertStringContainsString('/.well-known/', $messages[0]); } } public function testGoodCachedDiscoveryNeverWarns(): void { $notices = new AdminNotices($this->status(true, $this->realDiscoveryResult('good'), true)); self::assertSame([], $notices->messages(false)); } public function testDoesNotAddASeparateDiscoveryWarningWhenOAuthIsDisabled(): void { // HealthCheck::run_self_check()'s 'disabled' early return always reports status // 'good' and (like the permalink one below) is never persisted to its transient — // but we guard on the live oauthEnabled() state too rather than relying on that // vendor implementation detail. A stale 'critical' result cached from before OAuth // was disabled must not add a second, redundant notice. $notices = new AdminNotices($this->status(false, $this->realDiscoveryResult('critical'), true)); $messages = $notices->messages(false); self::assertCount(1, $messages); self::assertStringContainsString('OAuth-Server ist deaktiviert', $messages[0]); } public function testDoesNotWarnAboutDiscoveryWithoutPrettyPermalinks(): void { $notices = new AdminNotices($this->status(true, $this->realDiscoveryResult('recommended'), true, false)); self::assertSame([], $notices->messages(false)); } public function testHttpsHintOnlyOnTheSettingsPage(): void { $notices = new AdminNotices($this->status(true, null, false)); self::assertSame([], $notices->messages(false)); self::assertCount(1, $notices->messages(true)); } }