FIFO queue of post-arrays for tests. */ public static $_test_posts_queue = []; /** @var array */ public $posts = []; /** @var int */ public $found_posts = 0; /** @var bool */ public $have_posts = false; public function __construct( $args = [] ) { if ( ! empty( self::$_test_posts_queue ) ) { $this->posts = array_shift( self::$_test_posts_queue ); $this->found_posts = count( $this->posts ); $this->have_posts = $this->found_posts > 0; } } public function have_posts(): bool { return $this->have_posts; } public function the_post(): void { // No-op. } } } // NOTE: Do NOT stub wp_strip_all_tags() or sanitize_text_field() here. // Brain Monkey / Patchwork manages these stubs in individual tests via // Functions\when(). Defining them in bootstrap causes Patchwork's // "DefinedTooEarly" error. // WP_Error stub — used by model registry and image pipeline tests. // This is safe to define here because it's a class (not a function), // so Patchwork doesn't need to intercept its definition. if ( ! class_exists( 'WP_Error' ) ) { class WP_Error { public $errors = []; public $error_data = []; public function __construct( $code = '', $message = '', $data = '' ) { if ( $code ) { $this->errors[ $code ][] = $message; if ( $data ) { $this->error_data[ $code ] = $data; } } } public function get_error_code() { $codes = array_keys( $this->errors ); return $codes ? $codes[0] : ''; } public function get_error_message( $code = '' ) { if ( ! $code ) { $code = $this->get_error_code(); } return isset( $this->errors[ $code ] ) ? $this->errors[ $code ][0] : ''; } } } /** * Minimal WP_Post stub for unit tests. * * Board data provider tests return WP_Post instances from WP_Query. * Class defined here so instanceof checks in production code work correctly. */ if ( ! class_exists( 'WP_Post' ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound class WP_Post { /** @var int */ public $ID = 0; /** @var string */ public $post_title = ''; /** @var string */ public $post_status = 'publish'; /** @var string */ public $post_date_gmt = ''; /** @var string */ public $post_modified_gmt = ''; /** * @param array $data */ public function __construct( array $data = [] ) { foreach ( $data as $key => $value ) { $this->$key = $value; } } } } // Plugin URL and version constants used by admin enqueue methods. // Defined here so all tests that load admin classes can stub WP enqueue calls // without hitting "Undefined constant" errors. if ( ! defined( 'PRAUTOBLOGGER_DEFAULT_BOARD_COLUMN_LIMIT' ) ) { define( 'PRAUTOBLOGGER_DEFAULT_BOARD_COLUMN_LIMIT', 20 ); } // Plugin URL and version constants used by admin enqueue methods. if ( ! defined( 'PRAUTOBLOGGER_PLUGIN_URL' ) ) { define( 'PRAUTOBLOGGER_PLUGIN_URL', 'https://test.example.com/wp-content/plugins/prautoblogger/' ); } if ( ! defined( 'PRAUTOBLOGGER_VERSION' ) ) { define( 'PRAUTOBLOGGER_VERSION', '0.19.3-test' ); } if ( ! defined( 'PRAUTOBLOGGER_PLUGIN_DIR' ) ) { define( 'PRAUTOBLOGGER_PLUGIN_DIR', dirname( __DIR__ ) . '/' ); }