33// Load composer autoloader
44require_once __DIR__ . '/../vendor/autoload.php ' ;
55
6+ // Completely disable Patchwork to avoid redefinition conflicts
7+ if (class_exists ('Patchwork ' )) {
8+ // Disable all Patchwork functionality
9+ if (method_exists ('Patchwork ' , 'disable ' )) {
10+ Patchwork::disable ();
11+ }
12+ }
13+
14+ // Remove Patchwork from global functions if it exists
15+ if (isset ($ GLOBALS ['patchwork ' ])) {
16+ unset($ GLOBALS ['patchwork ' ]);
17+ }
18+
619// Check if WordPress test environment is available and load it
720$ wp_tests_dir = getenv ('WP_TESTS_DIR ' );
821if ($ wp_tests_dir && file_exists ($ wp_tests_dir . '/includes/bootstrap.php ' )) {
1124} else {
1225 // Fallback for local development without WordPress test suite
1326
14- // Load composer autoloader
15- require_once __DIR__ . '/../vendor/autoload.php ' ;
16-
17- // Disable Patchwork to avoid function redefinition issues
18- if (class_exists ('Patchwork\Utils ' )) {
19- Patchwork \Utils::disable ();
20- }
21-
22- // Create a no-op Patchwork setup
23- if (!class_exists ('Patchwork ' )) {
24- class Patchwork {
25- public static function redefine () { }
26- public static function restoreAll () { }
27- }
28- }
29-
3027 // Set up in-memory database for tests
3128 global $ wpdb , $ db ;
3229 if (!isset ($ wpdb )) {
@@ -38,7 +35,7 @@ public static function restoreAll() { }
3835 $ db = new PDO ('sqlite::memory: ' );
3936 $ db ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
4037
41- // Minimal WordPress schema
38+ // Create full WordPress schema for proper testing
4239 $ db ->exec ("
4340 CREATE TABLE wp_options (
4441 option_id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -47,6 +44,70 @@ public static function restoreAll() { }
4744 autoload VARCHAR(20) DEFAULT 'yes'
4845 );
4946 CREATE UNIQUE INDEX option_name_index ON wp_options (option_name);
47+
48+ CREATE TABLE wp_posts (
49+ ID INTEGER PRIMARY KEY AUTOINCREMENT,
50+ post_author INTEGER DEFAULT 0,
51+ post_date DATETIME DEFAULT '0000-00-00 00:00:00',
52+ post_date_gmt DATETIME DEFAULT '0000-00-00 00:00:00',
53+ post_content LONGTEXT,
54+ post_title TEXT,
55+ post_excerpt TEXT,
56+ post_status VARCHAR(20) DEFAULT 'publish',
57+ comment_status VARCHAR(20) DEFAULT 'open',
58+ ping_status VARCHAR(20) DEFAULT 'open',
59+ post_password VARCHAR(255),
60+ post_name VARCHAR(200),
61+ to_ping TEXT,
62+ pinged TEXT,
63+ post_modified DATETIME DEFAULT '0000-00-00 00:00:00',
64+ post_modified_gmt DATETIME DEFAULT '0000-00-00 00:00:00',
65+ post_content_filtered LONGTEXT,
66+ post_parent INTEGER DEFAULT 0,
67+ guid VARCHAR(255),
68+ menu_order INTEGER DEFAULT 0,
69+ post_type VARCHAR(20) DEFAULT 'post',
70+ post_mime_type VARCHAR(100),
71+ comment_count BIGINT DEFAULT 0
72+ );
73+ CREATE INDEX post_name_index ON wp_posts (post_name);
74+ CREATE INDEX type_status_date_index ON wp_posts (post_type, post_status, post_date, ID);
75+ CREATE INDEX post_parent_index ON wp_posts (post_parent);
76+ CREATE INDEX post_author_index ON wp_posts (post_author);
77+
78+ CREATE TABLE wp_postmeta (
79+ meta_id INTEGER PRIMARY KEY AUTOINCREMENT,
80+ post_id INTEGER DEFAULT 0,
81+ meta_key VARCHAR(255),
82+ meta_value LONGTEXT
83+ );
84+ CREATE INDEX post_id_index ON wp_postmeta (post_id);
85+ CREATE INDEX meta_key_index ON wp_postmeta (meta_key);
86+
87+ CREATE TABLE wp_users (
88+ ID INTEGER PRIMARY KEY AUTOINCREMENT,
89+ user_login VARCHAR(60) NOT NULL,
90+ user_pass VARCHAR(255) NOT NULL,
91+ user_nicename VARCHAR(50) NOT NULL,
92+ user_email VARCHAR(100) NOT NULL,
93+ user_url VARCHAR(100),
94+ user_registered DATETIME DEFAULT '0000-00-00 00:00:00',
95+ user_activation_key VARCHAR(255),
96+ user_status INTEGER DEFAULT 0,
97+ display_name VARCHAR(250)
98+ );
99+ CREATE UNIQUE INDEX user_login_key ON wp_users (user_login);
100+ CREATE INDEX user_nicename_index ON wp_users (user_nicename);
101+ CREATE INDEX user_email_index ON wp_users (user_email);
102+
103+ CREATE TABLE wp_usermeta (
104+ umeta_id INTEGER PRIMARY KEY AUTOINCREMENT,
105+ user_id INTEGER DEFAULT 0,
106+ meta_key VARCHAR(255),
107+ meta_value LONGTEXT
108+ );
109+ CREATE INDEX user_id_index ON wp_usermeta (user_id);
110+ CREATE INDEX meta_key_user_index ON wp_usermeta (meta_key);
50111 " );
51112
52113 // Mock WordPress functions for local testing
0 commit comments