Skip to content

Commit 50ad424

Browse files
committed
Tests: Add coverage for AI Client prompts when AI is unsupported
Adds a test to ensure `WP_AI_Client_Prompt_Builder::generate_result()` returns a `WP_Error` with the `prompt_prevented` code and the AI-disabled message when `wp_supports_ai()` returns false. Follow-up for #64591. Props nimeshatxecurify. Fixes #65422. git-svn-id: https://develop.svn.wordpress.org/trunk@62556 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f56b7f7 commit 50ad424

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,23 @@ public function test_generate_result_returns_wp_error_when_filter_prevents_promp
25612561
$this->assertSame( 'Prompt execution was prevented by a filter.', $result->get_error_message() );
25622562
}
25632563

2564+
/**
2565+
* Tests that generate_result returns WP_Error when AI is not supported.
2566+
*
2567+
* @ticket 65422
2568+
*/
2569+
public function test_generate_result_returns_wp_error_when_ai_not_supported() {
2570+
add_filter( 'wp_supports_ai', '__return_false' );
2571+
2572+
$builder = new WP_AI_Client_Prompt_Builder( AiClient::defaultRegistry(), 'Test prompt' );
2573+
2574+
$result = $builder->generate_result();
2575+
2576+
$this->assertWPError( $result );
2577+
$this->assertSame( 'prompt_prevented', $result->get_error_code() );
2578+
$this->assertSame( 'AI features are not supported in this environment.', $result->get_error_message() );
2579+
}
2580+
25642581
/**
25652582
* Tests that prevent prompt filter receives a clone of the builder instance.
25662583
*

0 commit comments

Comments
 (0)