diff --git a/includes/core/class-image-pipeline.php b/includes/core/class-image-pipeline.php index 1cdb085..02e1348 100644 --- a/includes/core/class-image-pipeline.php +++ b/includes/core/class-image-pipeline.php @@ -124,7 +124,9 @@ class PRAutoBlogger_Image_Pipeline { ? $image_a_result->get_error_message() : 'Image A generation produced no attachment ID.'; } - $result['cost_usd'] += $image_a_result['cost_usd'] ?? 0.0; + if ( ! is_wp_error( $image_a_result ) ) { + $result['cost_usd'] += $image_a_result['cost_usd'] ?? 0.0; + } // Generate Image B (source-driven prompt) if source data is available. if ( null !== $source_data && ! empty( $source_data ) ) { @@ -136,7 +138,9 @@ class PRAutoBlogger_Image_Pipeline { ? $image_b_result->get_error_message() : 'Image B generation produced no attachment ID.'; } - $result['cost_usd'] += $image_b_result['cost_usd'] ?? 0.0; + if ( ! is_wp_error( $image_b_result ) ) { + $result['cost_usd'] += $image_b_result['cost_usd'] ?? 0.0; + } } return $result; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 83714a7..6ff6748 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -55,6 +55,11 @@ if ( ! defined( 'PRAUTOBLOGGER_DEFAULT_EDITOR_MODEL' ) ) { define( 'PRAUTOBLOGGER_DEFAULT_EDITOR_MODEL', 'google/gemini-2.5-flash-lite' ); } +// Default image style suffix used by ImagePromptBuilder and settings UI. +if ( ! defined( 'PRAUTOBLOGGER_DEFAULT_IMAGE_STYLE_SUFFIX' ) ) { + define( 'PRAUTOBLOGGER_DEFAULT_IMAGE_STYLE_SUFFIX', 'Style: test infomercial style.' ); +} + // WordPress database constants used in $wpdb queries. if ( ! defined( 'ARRAY_A' ) ) { define( 'ARRAY_A', 'ARRAY_A' ); diff --git a/tests/unit/Core/ImagePipelineTest.php b/tests/unit/Core/ImagePipelineTest.php index 63e8164..d04b8a8 100644 --- a/tests/unit/Core/ImagePipelineTest.php +++ b/tests/unit/Core/ImagePipelineTest.php @@ -19,6 +19,9 @@ class ImagePipelineTest extends BaseTestCase { parent::setUp(); // Mock WordPress functions used by the pipeline and its dependencies. + Functions\when( 'is_wp_error' )->alias( function ( $thing ) { + return $thing instanceof \WP_Error; + } ); Functions\when( 'wp_generate_uuid4' )->justReturn( 'test-uuid' ); Functions\when( 'get_option' )->alias( function ( $key, $default = false ) { static $options = [ @@ -32,6 +35,8 @@ class ImagePipelineTest extends BaseTestCase { return trim( strip_tags( $str ) ); } ); Functions\when( 'update_post_meta' )->justReturn( true ); + Functions\when( 'sanitize_title' )->returnArg(); + Functions\when( 'esc_html__' )->returnArg(); } /**