@@ -54,6 +54,15 @@ public static function wpSetUpBeforeClass( $factory ) {
54
54
);
55
55
}
56
56
57
+ /**
58
+ * Load mock Manager class for specific tests.
59
+ */
60
+ private function load_mock_manager () {
61
+ if ( ! class_exists ( '\Automattic\Jetpack\Connection\Manager ' ) ) {
62
+ require_once AP_TESTS_DIR . '/data/class-manager.php ' ;
63
+ }
64
+ }
65
+
57
66
/**
58
67
* Clean up after tests.
59
68
*/
@@ -71,42 +80,80 @@ public function tear_down() {
71
80
}
72
81
73
82
/**
74
- * Test init method registers sync hooks correctly.
83
+ * Test init method registers sync hooks without Manager class.
84
+ *
85
+ * This test must run before the Manager class is loaded to test the behavior
86
+ * when the class doesn't exist.
75
87
*
76
88
* @covers ::init
77
89
*/
78
- public function test_init_registers_sync_hooks () {
90
+ public function test_a_init_registers_sync_hooks_without_manager () {
91
+ // Verify Manager class is not yet loaded.
92
+ $ this ->assertFalse ( class_exists ( '\Automattic\Jetpack\Connection\Manager ' ), 'Manager class should not exist yet ' );
93
+
79
94
// Ensure hooks are not already registered.
80
95
$ this ->assertFalse ( has_filter ( 'jetpack_sync_post_meta_whitelist ' ) );
96
+ $ this ->assertFalse ( has_filter ( 'activitypub_following_row_actions ' ) );
97
+ $ this ->assertFalse ( has_filter ( 'pre_option_activitypub_following_ui ' ) );
81
98
82
- // Initialize Jetpack integration.
99
+ // Initialize Jetpack integration without Manager class loaded .
83
100
Jetpack::init ();
84
101
85
- // Check that sync hooks are registered (when not on WordPress.com) .
102
+ // Check that sync hooks are registered regardless of Manager class .
86
103
$ this ->assertTrue ( has_filter ( 'jetpack_sync_post_meta_whitelist ' ) );
87
104
$ this ->assertTrue ( has_filter ( 'jetpack_sync_comment_meta_whitelist ' ) );
88
105
$ this ->assertTrue ( has_filter ( 'jetpack_sync_whitelisted_comment_types ' ) );
89
106
$ this ->assertTrue ( has_filter ( 'jetpack_json_api_comment_types ' ) );
90
107
$ this ->assertTrue ( has_filter ( 'jetpack_api_include_comment_types_count ' ) );
108
+
109
+ // Following UI hooks should NOT be registered without Manager class.
110
+ $ this ->assertFalse ( has_filter ( 'activitypub_following_row_actions ' ) );
111
+ $ this ->assertFalse ( has_filter ( 'pre_option_activitypub_following_ui ' ) );
91
112
}
92
113
93
114
/**
94
- * Test that following UI hooks are not registered without proper conditions .
115
+ * Test init method registers all hooks with Manager class available .
95
116
*
96
117
* @covers ::init
97
118
*/
98
- public function test_init_skips_following_ui_hooks_without_conditions () {
119
+ public function test_b_init_registers_hooks_with_manager () {
120
+ // Load mock Manager class.
121
+ $ this ->load_mock_manager ();
122
+
99
123
// Ensure hooks are not already registered.
124
+ $ this ->assertFalse ( has_filter ( 'jetpack_sync_post_meta_whitelist ' ) );
100
125
$ this ->assertFalse ( has_filter ( 'activitypub_following_row_actions ' ) );
101
126
$ this ->assertFalse ( has_filter ( 'pre_option_activitypub_following_ui ' ) );
102
127
103
- // Initialize Jetpack integration.
128
+ // Initialize Jetpack integration with Manager class .
104
129
Jetpack::init ();
105
130
106
- // Following UI hooks should NOT be registered in test environment
107
- // because neither IS_WPCOM is defined nor is Jetpack connected.
108
- $ this ->assertFalse ( has_filter ( 'activitypub_following_row_actions ' ) );
109
- $ this ->assertFalse ( has_filter ( 'pre_option_activitypub_following_ui ' ) );
131
+ // Check that sync hooks are registered.
132
+ $ this ->assertTrue ( has_filter ( 'jetpack_sync_post_meta_whitelist ' ) );
133
+ $ this ->assertTrue ( has_filter ( 'jetpack_sync_comment_meta_whitelist ' ) );
134
+ $ this ->assertTrue ( has_filter ( 'jetpack_sync_whitelisted_comment_types ' ) );
135
+ $ this ->assertTrue ( has_filter ( 'jetpack_json_api_comment_types ' ) );
136
+ $ this ->assertTrue ( has_filter ( 'jetpack_api_include_comment_types_count ' ) );
137
+
138
+ // Following UI hooks should also be registered (mock Manager returns connected).
139
+ $ this ->assertTrue ( has_filter ( 'activitypub_following_row_actions ' ) );
140
+ $ this ->assertTrue ( has_filter ( 'pre_option_activitypub_following_ui ' ) );
141
+ }
142
+
143
+ /**
144
+ * Test that Manager class connection check works when available.
145
+ *
146
+ * @covers ::init
147
+ */
148
+ public function test_c_manager_connection_check () {
149
+ // Load mock Manager class.
150
+ $ this ->load_mock_manager ();
151
+
152
+ // Test that our mock Manager class exists and works.
153
+ $ this ->assertTrue ( class_exists ( '\Automattic\Jetpack\Connection\Manager ' ), 'Mock Manager class should exist ' );
154
+
155
+ $ manager = new \Automattic \Jetpack \Connection \Manager ();
156
+ $ this ->assertTrue ( $ manager ->is_user_connected (), 'Mock Manager should return connected ' );
110
157
}
111
158
112
159
/**
0 commit comments