@@ -19,21 +19,21 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
1919 self ::$ post_id = $ factory ->post ->create ( array ( 'post_author ' => self ::$ editor_id ) );
2020
2121 // Enable option in setUpBeforeClass to ensure REST routes are registered.
22- update_option ( 'wp_collaboration_enabled ' , 1 );
22+ add_filter ( 'pre_option_wp_collaboration_enabled ' , ' __return_true ' );
2323 }
2424
2525 public static function wpTearDownAfterClass () {
2626 self ::delete_user ( self ::$ editor_id );
2727 self ::delete_user ( self ::$ subscriber_id );
28- delete_option ( 'wp_collaboration_enabled ' );
28+ remove_filter ( 'pre_option_wp_collaboration_enabled ' , ' __return_true ' );
2929 wp_delete_post ( self ::$ post_id , true );
3030 }
3131
3232 public function set_up () {
3333 parent ::set_up ();
3434
3535 // Enable option for tests.
36- update_option ( 'wp_collaboration_enabled ' , 1 );
36+ add_filter ( 'pre_option_wp_collaboration_enabled ' , ' __return_true ' );
3737
3838 // Uses DELETE (not TRUNCATE) to preserve transaction rollback support
3939 // in the test suite. TRUNCATE implicitly commits the transaction.
@@ -102,25 +102,6 @@ public function test_register_routes(): void {
102102 $ this ->assertArrayHasKey ( '/wp-collaboration/v1/updates ' , $ routes );
103103 }
104104
105- /**
106- * Verifies the collaboration route is not registered when the option is
107- * not stored in the database (default is off).
108- *
109- * @ticket 64814
110- */
111- public function test_register_routes_without_option (): void {
112- global $ wp_rest_server ;
113-
114- // Ensure the option is not in the database.
115- delete_option ( 'wp_collaboration_enabled ' );
116-
117- // Reset the REST server so routes are re-registered from scratch.
118- $ wp_rest_server = null ;
119-
120- $ routes = rest_get_server ()->get_routes ();
121- $ this ->assertArrayNotHasKey ( '/wp-collaboration/v1/updates ' , $ routes );
122- }
123-
124105 /**
125106 * @doesNotPerformAssertions
126107 */
@@ -2001,7 +1982,7 @@ public function test_cron_cleanup_when_collaboration_disabled(): void {
20011982 $ this ->assertIsInt ( wp_next_scheduled ( 'wp_delete_old_collaboration_data ' ), 'Cron event should be scheduled before cleanup. ' );
20021983
20031984 // Disable collaboration.
2004- update_option ( 'wp_collaboration_enabled ' , false );
1985+ add_filter ( 'pre_option_wp_collaboration_enabled ' , ' __return_zero ' ); // __return_false fails for pre-flight hook.
20051986
20061987 wp_delete_old_collaboration_data ();
20071988
@@ -2051,18 +2032,23 @@ public function test_cron_cleanup_preserves_fresh_awareness_rows(): void {
20512032 * @ticket 64696
20522033 */
20532034 public function test_collaboration_routes_not_registered_when_db_version_is_old (): void {
2054- update_option ( 'db_version ' , 61839 );
2035+ add_filter (
2036+ 'pre_option_db_version ' ,
2037+ static function () {
2038+ return 61839 ; // Lower than required version.
2039+ }
2040+ );
20552041
20562042 // Reset the global REST server so rest_get_server() builds a fresh instance.
20572043 $ GLOBALS ['wp_rest_server ' ] = null ;
20582044
20592045 $ server = rest_get_server ();
20602046 $ routes = $ server ->get_routes ();
20612047
2062- $ this ->assertArrayNotHasKey ( '/wp-collaboration/v1/updates ' , $ routes , 'Collaboration routes should not be registered when db_version is below 61841. ' );
2063-
2064- // Reset again so subsequent tests get a server with the correct db_version.
2048+ // Reset again so subsequent tests get a server with the correct db_version, done prior to assertion to ensure this runs when an exception is thrown.
20652049 $ GLOBALS ['wp_rest_server ' ] = null ;
2050+
2051+ $ this ->assertArrayNotHasKey ( '/wp-collaboration/v1/updates ' , $ routes , 'Collaboration routes should not be registered when db_version is below 61841. ' );
20662052 }
20672053
20682054 /*
@@ -2788,7 +2774,7 @@ public function test_collaboration_taxonomy_term_wrong_taxonomy_rejected(): void
27882774 * @ticket 64696
27892775 */
27902776 public function test_wp_is_collaboration_enabled_true_when_both_conditions_met (): void {
2791- update_option ( 'wp_collaboration_enabled ' , 1 );
2777+ add_filter ( 'pre_option_wp_collaboration_enabled ' , ' __return_true ' );
27922778
27932779 $ this ->assertTrue ( wp_is_collaboration_enabled () );
27942780 }
@@ -2800,8 +2786,13 @@ public function test_wp_is_collaboration_enabled_true_when_both_conditions_met()
28002786 * @ticket 64696
28012787 */
28022788 public function test_wp_is_collaboration_enabled_false_when_db_version_too_low (): void {
2803- update_option ( 'wp_collaboration_enabled ' , 1 );
2804- update_option ( 'db_version ' , 61839 );
2789+ add_filter ( 'pre_option_wp_collaboration_enabled ' , '__return_true ' );
2790+ add_filter (
2791+ 'pre_option_db_version ' ,
2792+ static function () {
2793+ return 61839 ; // Lower than required version.
2794+ }
2795+ );
28052796
28062797 $ this ->assertFalse ( wp_is_collaboration_enabled () );
28072798 }
@@ -2813,7 +2804,7 @@ public function test_wp_is_collaboration_enabled_false_when_db_version_too_low()
28132804 * @ticket 64696
28142805 */
28152806 public function test_wp_is_collaboration_enabled_false_when_option_off (): void {
2816- update_option ( 'wp_collaboration_enabled ' , 0 );
2807+ add_filter ( 'pre_option_wp_collaboration_enabled ' , ' __return_zero ' ); // __return_false fails
28172808
28182809 $ this ->assertFalse ( wp_is_collaboration_enabled () );
28192810 }
0 commit comments