@@ -570,9 +570,6 @@ public function test_rest_autosave_published_post() {
570570 }
571571
572572 public function test_rest_autosave_draft_post_same_author () {
573- $ original_option = get_option ( 'enable_real_time_collaboration ' );
574- update_option ( 'enable_real_time_collaboration ' , false );
575-
576573 wp_set_current_user ( self ::$ editor_id );
577574
578575 $ post_data = array (
@@ -592,10 +589,15 @@ public function test_rest_autosave_draft_post_same_author() {
592589 $ request ->add_header ( 'Content-Type ' , 'application/json ' );
593590 $ request ->set_body ( wp_json_encode ( $ autosave_data ) );
594591
592+ // Behavior differs depending on whether real-time collaboration is enabled.
593+ add_filter ( 'pre_option_enable_real_time_collaboration ' , '__return_zero ' );
594+
595595 $ response = rest_get_server ()->dispatch ( $ request );
596596 $ new_data = $ response ->get_data ();
597597 $ post = get_post ( $ post_id );
598598
599+ remove_filter ( 'pre_option_enable_real_time_collaboration ' , '__return_zero ' );
600+
599601 $ this ->assertSame ( $ post_id , $ new_data ['id ' ] );
600602 // The draft post should be updated.
601603 $ this ->assertSame ( $ autosave_data ['content ' ], $ new_data ['content ' ]['raw ' ] );
@@ -607,7 +609,6 @@ public function test_rest_autosave_draft_post_same_author() {
607609 $ this ->assertSame ( $ post_data ['post_excerpt ' ], $ post ->post_excerpt );
608610
609611 wp_delete_post ( $ post_id );
610- update_option ( 'enable_real_time_collaboration ' , $ original_option );
611612 }
612613
613614 public function test_rest_autosave_draft_post_different_author () {
@@ -748,9 +749,6 @@ public function test_get_item_sets_up_postdata() {
748749 }
749750
750751 public function test_update_item_draft_page_with_parent () {
751- $ original_option = get_option ( 'enable_real_time_collaboration ' );
752- update_option ( 'enable_real_time_collaboration ' , false );
753-
754752 wp_set_current_user ( self ::$ editor_id );
755753 $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/pages/ ' . self ::$ child_draft_page_id . '/autosaves ' );
756754 $ request ->add_header ( 'Content-Type ' , 'application/x-www-form-urlencoded ' );
@@ -762,13 +760,18 @@ public function test_update_item_draft_page_with_parent() {
762760 )
763761 );
764762
763+ // Behavior differs depending on whether real-time collaboration is enabled.
764+ add_filter ( 'pre_option_enable_real_time_collaboration ' , '__return_zero ' );
765+
765766 $ request ->set_body_params ( $ params );
766767 $ response = rest_get_server ()->dispatch ( $ request );
767768 $ data = $ response ->get_data ();
768769
770+ remove_filter ( 'pre_option_enable_real_time_collaboration ' , '__return_zero ' );
771+
769772 $ this ->assertSame ( self ::$ child_draft_page_id , $ data ['id ' ] );
770773 $ this ->assertSame ( self ::$ parent_page_id , $ data ['parent ' ] );
771- update_option ( ' enable_real_time_collaboration ' , $ original_option );
774+
772775 }
773776
774777 public function test_schema_validation_is_applied () {
@@ -932,11 +935,10 @@ public static function data_head_request_with_specified_fields_returns_success_r
932935 /**
933936 * When real-time collaboration is enabled, autosaving a draft post by the
934937 * same author should create a revision instead of updating the post directly.
938+ *
939+ * @ticket 64622
935940 */
936941 public function test_rest_autosave_draft_post_same_author_with_rtc () {
937- $ original_option = get_option ( 'enable_real_time_collaboration ' );
938- update_option ( 'enable_real_time_collaboration ' , true );
939-
940942 wp_set_current_user ( self ::$ editor_id );
941943
942944 $ post_data = array (
@@ -952,6 +954,9 @@ public function test_rest_autosave_draft_post_same_author_with_rtc() {
952954 'title ' => 'Updated post title ' ,
953955 );
954956
957+ // Behavior differs depending on whether real-time collaboration is enabled.
958+ add_filter ( 'pre_option_enable_real_time_collaboration ' , '__return_true ' );
959+
955960 $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/posts/ ' . self ::$ post_id . '/autosaves ' );
956961 $ request ->add_header ( 'Content-Type ' , 'application/json ' );
957962 $ request ->set_body ( wp_json_encode ( $ autosave_data ) );
@@ -960,6 +965,8 @@ public function test_rest_autosave_draft_post_same_author_with_rtc() {
960965 $ new_data = $ response ->get_data ();
961966 $ post = get_post ( $ post_id );
962967
968+ remove_filter ( 'pre_option_enable_real_time_collaboration ' , '__return_true ' );
969+
963970 // With RTC enabled, a revision is created instead of updating the post.
964971 $ this ->assertNotSame ( $ post_id , $ new_data ['id ' ] );
965972 $ this ->assertSame ( $ post_id , $ new_data ['parent ' ] );
@@ -974,17 +981,13 @@ public function test_rest_autosave_draft_post_same_author_with_rtc() {
974981 $ this ->assertSame ( $ post_data ['post_excerpt ' ], $ post ->post_excerpt );
975982
976983 wp_delete_post ( $ post_id );
977- update_option ( 'enable_real_time_collaboration ' , $ original_option );
978984 }
979985
980986 /**
981987 * When real-time collaboration is enabled, autosaving a draft page with
982988 * a parent should create a revision instead of updating the page directly.
983989 */
984990 public function test_update_item_draft_page_with_parent_with_rtc () {
985- $ original_option = get_option ( 'enable_real_time_collaboration ' );
986- update_option ( 'enable_real_time_collaboration ' , true );
987-
988991 wp_set_current_user ( self ::$ editor_id );
989992 $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/pages/ ' . self ::$ child_draft_page_id . '/autosaves ' );
990993 $ request ->add_header ( 'Content-Type ' , 'application/x-www-form-urlencoded ' );
@@ -996,13 +999,17 @@ public function test_update_item_draft_page_with_parent_with_rtc() {
996999 )
9971000 );
9981001
1002+ // Behavior differs depending on whether real-time collaboration is enabled.
1003+ add_filter ( 'pre_option_enable_real_time_collaboration ' , '__return_true ' );
1004+
9991005 $ request ->set_body_params ( $ params );
10001006 $ response = rest_get_server ()->dispatch ( $ request );
10011007 $ data = $ response ->get_data ();
10021008
1009+ remove_filter ( 'pre_option_enable_real_time_collaboration ' , '__return_true ' );
1010+
10031011 // With RTC enabled, a revision is created instead of updating the page.
10041012 $ this ->assertNotSame ( self ::$ child_draft_page_id , $ data ['id ' ] );
10051013 $ this ->assertSame ( self ::$ child_draft_page_id , $ data ['parent ' ] );
1006- update_option ( 'enable_real_time_collaboration ' , $ original_option );
10071014 }
10081015}
0 commit comments