@@ -54,6 +54,15 @@ public static function wpSetUpBeforeClass( $factory ) {
5454 );
5555 }
5656
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+
5766 /**
5867 * Clean up after tests.
5968 */
@@ -71,42 +80,80 @@ public function tear_down() {
7180 }
7281
7382 /**
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.
7587 *
7688 * @covers ::init
7789 */
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+
7994 // Ensure hooks are not already registered.
8095 $ 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 ' ) );
8198
82- // Initialize Jetpack integration.
99+ // Initialize Jetpack integration without Manager class loaded .
83100 Jetpack::init ();
84101
85- // Check that sync hooks are registered (when not on WordPress.com) .
102+ // Check that sync hooks are registered regardless of Manager class .
86103 $ this ->assertTrue ( has_filter ( 'jetpack_sync_post_meta_whitelist ' ) );
87104 $ this ->assertTrue ( has_filter ( 'jetpack_sync_comment_meta_whitelist ' ) );
88105 $ this ->assertTrue ( has_filter ( 'jetpack_sync_whitelisted_comment_types ' ) );
89106 $ this ->assertTrue ( has_filter ( 'jetpack_json_api_comment_types ' ) );
90107 $ 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 ' ) );
91112 }
92113
93114 /**
94- * Test that following UI hooks are not registered without proper conditions .
115+ * Test init method registers all hooks with Manager class available .
95116 *
96117 * @covers ::init
97118 */
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+
99123 // Ensure hooks are not already registered.
124+ $ this ->assertFalse ( has_filter ( 'jetpack_sync_post_meta_whitelist ' ) );
100125 $ this ->assertFalse ( has_filter ( 'activitypub_following_row_actions ' ) );
101126 $ this ->assertFalse ( has_filter ( 'pre_option_activitypub_following_ui ' ) );
102127
103- // Initialize Jetpack integration.
128+ // Initialize Jetpack integration with Manager class .
104129 Jetpack::init ();
105130
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 ' );
110157 }
111158
112159 /**
0 commit comments