From 9f267342a094221857ecffe0c55509ce60925a24 Mon Sep 17 00:00:00 2001 From: Terence Ong Date: Mon, 6 Apr 2026 14:26:31 +0700 Subject: [PATCH] Fix pre-existing PHPUnit test failures in CI Add missing WordPress function stubs (current_user_can, esc_url_raw, is_user_logged_in, get_current_user_id) and load LLM class in test bootstrap so AdminTest model validation and RestApiTest permission checks work correctly. Co-Authored-By: Claude Opus 4.6 --- tests/bootstrap.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8ed6bd9..ced6b39 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -154,6 +154,27 @@ if ( ! function_exists( 'esc_html__' ) ) { return esc_html( $text ); } } +if ( ! function_exists( 'esc_url_raw' ) ) { + function esc_url_raw( $url, $protocols = null ) { + return filter_var( $url, FILTER_SANITIZE_URL ) ?: ''; + } +} +if ( ! function_exists( 'current_user_can' ) ) { + function current_user_can( $capability ) { + global $_test_current_user_can; + return ! empty( $_test_current_user_can ); + } +} +if ( ! function_exists( 'is_user_logged_in' ) ) { + function is_user_logged_in() { + return false; + } +} +if ( ! function_exists( 'get_current_user_id' ) ) { + function get_current_user_id() { + return 0; + } +} // Stub WP_Error for permission checks. if ( ! class_exists( 'WP_Error' ) ) { @@ -188,6 +209,9 @@ if ( ! class_exists( 'WP_Error' ) ) { // Content filter can be loaded standalone (no WordPress runtime needed). require_once PEPTIDE_NEWS_PLUGIN_DIR . 'includes/class-peptide-news-content-filter.php'; +// LLM class provides is_valid_model() used by Admin sanitize callbacks. +require_once PEPTIDE_NEWS_PLUGIN_DIR . 'includes/class-peptide-news-llm.php'; + // Stub WP_REST_Request for REST API tests. if ( ! class_exists( 'WP_REST_Request' ) ) { class WP_REST_Request {