Skip to content

Commit 2139778

Browse files
Tests: Cover post_lock_window in wp_heartbeat_set_suspension().
Add coverage for the heartbeat setting exposed in [r/PR WordPress#11732]: - post_lock_window is set to the default 150 on post.php and post-new.php. - post_lock_window is omitted on non-post screens (index.php, edit.php). - post_lock_window reflects the wp_check_post_lock_window filter value. See #65171.
1 parent a58bab7 commit 2139778

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

tests/phpunit/tests/admin/includes/misc/WpHeartbeatSetSuspension_Test.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)