File: /var/www/html/wp-content/themes/custom-theme/tests/bootstrap.php
<?php
// Define WordPress constants to allow functions.php to load
define('ABSPATH', '/tmp/wordpress/');
define('WP_DEBUG', true);
// Stub WordPress functions called at file inclusion time
function add_action($hook = '', $callback = null, $priority = 10, $accepted_args = 1) {}
function add_filter($hook = '', $callback = null, $priority = 10, $accepted_args = 1) {}
function is_admin() { return false; }
function wp_doing_cron() { return false; }
function get_stylesheet_directory() { return dirname(__DIR__); }
function wp_redirect($url, $status = 302) {}
function register_post_type($post_type, $args = []) {}
$GLOBALS['_mock_get_field'] = null;
function get_field($selector, $post_id = false) {
if ($GLOBALS['_mock_get_field']) {
return ($GLOBALS['_mock_get_field'])($selector, $post_id);
}
return '';
}
function get_attached_file($attachment_id) { return ''; }
// Mockable WordPress functions for typesense indexing tests
$GLOBALS['_mock_wp_get_attachment_image_url'] = null;
$GLOBALS['_mock_wp_get_attachment_metadata'] = null;
$GLOBALS['_mock_wp_get_attachment_url'] = null;
function wp_get_attachment_image_url($attachment_id, $size = 'thumbnail') {
if ($GLOBALS['_mock_wp_get_attachment_image_url']) {
return ($GLOBALS['_mock_wp_get_attachment_image_url'])($attachment_id, $size);
}
return '';
}
function wp_get_attachment_metadata($attachment_id) {
if ($GLOBALS['_mock_wp_get_attachment_metadata']) {
return ($GLOBALS['_mock_wp_get_attachment_metadata'])($attachment_id);
}
return [];
}
function wp_get_attachment_url($attachment_id) {
if ($GLOBALS['_mock_wp_get_attachment_url']) {
return ($GLOBALS['_mock_wp_get_attachment_url'])($attachment_id);
}
return '';
}
// Mockable WordPress functions — override via $GLOBALS in tests
$GLOBALS['_mock_wp_get_attachment_image_src'] = null;
$GLOBALS['_mock_get_post_meta'] = null;
function wp_get_attachment_image_src($id, $size = 'thumbnail') {
if ($GLOBALS['_mock_wp_get_attachment_image_src']) {
return ($GLOBALS['_mock_wp_get_attachment_image_src'])($id, $size);
}
return false;
}
function get_post_meta($post_id, $key = '', $single = false) {
if ($GLOBALS['_mock_get_post_meta']) {
return ($GLOBALS['_mock_get_post_meta'])($post_id, $key, $single);
}
return '';
}
// Load the theme functions
require_once dirname(__DIR__) . '/functions.php';