From 01cae35d9e3a98f55da04ceff3d3550af31be0ee Mon Sep 17 00:00:00 2001 From: Nimesh Date: Fri, 5 Jun 2026 17:12:55 +0530 Subject: [PATCH] Tests: Add test for AI support check in WP_AI_Client_Prompt_Builder. Ensure that `generate_result()` returns a `WP_Error` with the `prompt_prevented` code when AI features are not supported in the environment. --- .../tests/ai-client/wpAiClientPromptBuilder.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php b/tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php index e758a6868aa42..9e8fa8d8f2a86 100644 --- a/tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php +++ b/tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php @@ -2561,6 +2561,23 @@ public function test_generate_result_returns_wp_error_when_filter_prevents_promp $this->assertSame( 'Prompt execution was prevented by a filter.', $result->get_error_message() ); } + /** + * Tests that generate_result returns WP_Error when AI is not supported. + * + * @ticket 65422 + */ + public function test_generate_result_returns_wp_error_when_ai_not_supported() { + add_filter( 'wp_supports_ai', '__return_false' ); + + $builder = new WP_AI_Client_Prompt_Builder( AiClient::defaultRegistry(), 'Test prompt' ); + + $result = $builder->generate_result(); + + $this->assertWPError( $result ); + $this->assertSame( 'prompt_prevented', $result->get_error_code() ); + $this->assertSame( 'AI features are not supported in this environment.', $result->get_error_message() ); + } + /** * Tests that prevent prompt filter receives a clone of the builder instance. *