@@ -79,4 +79,89 @@ public function data_wp_heartbeat_set_suspension(): array {
7979 ),
8080 );
8181 }
82+
83+ /**
84+ * Tests that wp_heartbeat_set_suspension() exposes the default post lock window on post screens.
85+ *
86+ * @dataProvider data_post_screens
87+ *
88+ * @ticket 65171
89+ *
90+ * @param string $pagenow_value The value for the $pagenow global.
91+ */
92+ public function test_wp_heartbeat_set_suspension_sets_post_lock_window_on_post_screens ( $ pagenow_value ) {
93+ global $ pagenow ;
94+
95+ $ pagenow = $ pagenow_value ;
96+
97+ $ result = wp_heartbeat_set_suspension ( array () );
98+
99+ $ this ->assertArrayHasKey ( 'post_lock_window ' , $ result , "'post_lock_window' should be present when \$pagenow is {$ pagenow_value }. " );
100+ $ this ->assertSame ( 150 , $ result ['post_lock_window ' ], "'post_lock_window' should default to 150 when \$pagenow is {$ pagenow_value }. " );
101+ }
102+
103+ /**
104+ * Tests that wp_heartbeat_set_suspension() does not expose a post lock window on non-post screens.
105+ *
106+ * @dataProvider data_non_post_screens
107+ *
108+ * @ticket 65171
109+ *
110+ * @param string $pagenow_value The value for the $pagenow global.
111+ */
112+ public function test_wp_heartbeat_set_suspension_does_not_set_post_lock_window_on_other_screens ( $ pagenow_value ) {
113+ global $ pagenow ;
114+
115+ $ pagenow = $ pagenow_value ;
116+
117+ $ result = wp_heartbeat_set_suspension ( array () );
118+
119+ $ this ->assertArrayNotHasKey ( 'post_lock_window ' , $ result , "'post_lock_window' should not be set when \$pagenow is {$ pagenow_value }. " );
120+ }
121+
122+ /**
123+ * Tests that wp_heartbeat_set_suspension() honors the wp_check_post_lock_window filter.
124+ *
125+ * @ticket 65171
126+ */
127+ public function test_wp_heartbeat_set_suspension_post_lock_window_respects_filter () {
128+ global $ pagenow ;
129+
130+ $ pagenow = 'post.php ' ;
131+
132+ add_filter (
133+ 'wp_check_post_lock_window ' ,
134+ static function () {
135+ return 60 ;
136+ }
137+ );
138+
139+ $ result = wp_heartbeat_set_suspension ( array () );
140+
141+ $ this ->assertSame ( 60 , $ result ['post_lock_window ' ], "'post_lock_window' should reflect the wp_check_post_lock_window filter value. " );
142+ }
143+
144+ /**
145+ * Data provider: $pagenow values for the Add/Edit Post screens.
146+ *
147+ * @return array<string, array{pagenow_value: string}>
148+ */
149+ public function data_post_screens (): array {
150+ return array (
151+ 'post.php ' => array ( 'pagenow_value ' => 'post.php ' ),
152+ 'post-new.php ' => array ( 'pagenow_value ' => 'post-new.php ' ),
153+ );
154+ }
155+
156+ /**
157+ * Data provider: $pagenow values for screens that are not Add/Edit Post.
158+ *
159+ * @return array<string, array{pagenow_value: string}>
160+ */
161+ public function data_non_post_screens (): array {
162+ return array (
163+ 'index.php ' => array ( 'pagenow_value ' => 'index.php ' ),
164+ 'edit.php ' => array ( 'pagenow_value ' => 'edit.php ' ),
165+ );
166+ }
82167}
0 commit comments