|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests for wp_ai_client_prompt(). |
| 4 | + * |
| 5 | + * @group ai-client |
| 6 | + * @covers ::wp_ai_client_prompt |
| 7 | + */ |
| 8 | + |
| 9 | +use WordPress\AiClient\Builders\PromptBuilder; |
| 10 | + |
| 11 | +class Tests_AI_Client_Prompt extends WP_UnitTestCase { |
| 12 | + |
| 13 | + /** |
| 14 | + * Test that wp_ai_client_prompt() returns a WP_AI_Client_Prompt_Builder instance. |
| 15 | + * |
| 16 | + * @ticket TBD |
| 17 | + */ |
| 18 | + public function test_returns_prompt_builder_instance() { |
| 19 | + $builder = wp_ai_client_prompt(); |
| 20 | + |
| 21 | + $this->assertInstanceOf( WP_AI_Client_Prompt_Builder::class, $builder ); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Test that wp_ai_client_prompt() wraps a PromptBuilder internally. |
| 26 | + * |
| 27 | + * @ticket TBD |
| 28 | + */ |
| 29 | + public function test_wraps_sdk_prompt_builder() { |
| 30 | + $builder = wp_ai_client_prompt(); |
| 31 | + |
| 32 | + $reflection = new ReflectionClass( WP_AI_Client_Prompt_Builder::class ); |
| 33 | + $property = $reflection->getProperty( 'builder' ); |
| 34 | + $property->setAccessible( true ); |
| 35 | + |
| 36 | + $this->assertInstanceOf( PromptBuilder::class, $property->getValue( $builder ) ); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Test that wp_ai_client_prompt() passes prompt content to the builder. |
| 41 | + * |
| 42 | + * @ticket TBD |
| 43 | + */ |
| 44 | + public function test_passes_prompt_content() { |
| 45 | + $builder = wp_ai_client_prompt( 'Hello, AI!' ); |
| 46 | + |
| 47 | + $reflection = new ReflectionClass( WP_AI_Client_Prompt_Builder::class ); |
| 48 | + $builder_property = $reflection->getProperty( 'builder' ); |
| 49 | + $builder_property->setAccessible( true ); |
| 50 | + $wrapped = $builder_property->getValue( $builder ); |
| 51 | + |
| 52 | + $wrapped_reflection = new ReflectionClass( get_class( $wrapped ) ); |
| 53 | + $messages_property = $wrapped_reflection->getProperty( 'messages' ); |
| 54 | + $messages_property->setAccessible( true ); |
| 55 | + $messages = $messages_property->getValue( $wrapped ); |
| 56 | + |
| 57 | + $this->assertNotEmpty( $messages, 'Prompt content should produce at least one message.' ); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Test that wp_ai_client_prompt() without arguments creates builder with no messages. |
| 62 | + * |
| 63 | + * @ticket TBD |
| 64 | + */ |
| 65 | + public function test_no_prompt_creates_empty_builder() { |
| 66 | + $builder = wp_ai_client_prompt(); |
| 67 | + |
| 68 | + $reflection = new ReflectionClass( WP_AI_Client_Prompt_Builder::class ); |
| 69 | + $builder_property = $reflection->getProperty( 'builder' ); |
| 70 | + $builder_property->setAccessible( true ); |
| 71 | + $wrapped = $builder_property->getValue( $builder ); |
| 72 | + |
| 73 | + $wrapped_reflection = new ReflectionClass( get_class( $wrapped ) ); |
| 74 | + $messages_property = $wrapped_reflection->getProperty( 'messages' ); |
| 75 | + $messages_property->setAccessible( true ); |
| 76 | + $messages = $messages_property->getValue( $wrapped ); |
| 77 | + |
| 78 | + $this->assertEmpty( $messages, 'No prompt content should produce no messages.' ); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Test that successive calls return independent builder instances. |
| 83 | + * |
| 84 | + * @ticket TBD |
| 85 | + */ |
| 86 | + public function test_returns_independent_instances() { |
| 87 | + $builder1 = wp_ai_client_prompt( 'First' ); |
| 88 | + $builder2 = wp_ai_client_prompt( 'Second' ); |
| 89 | + |
| 90 | + $this->assertNotSame( $builder1, $builder2 ); |
| 91 | + } |
| 92 | +} |
0 commit comments