Skip to content

Commit a5c8c1a

Browse files
committed
Updating test suite
1 parent ada9898 commit a5c8c1a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/phpunit/tests/post/wpUpdatePost.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,17 @@ public function test_wp_update_post_with_content_filtering() {
196196
* @param string $time_offset Time offset.
197197
* @param string $expected_status Expected post status.
198198
*/
199-
public function test_update_post_preserves_date_for_future_posts( $initial_status, $time_offset, $expected_status ) {
199+
public function test_update_post_preserves_date_for_future_posts( $initial_status, $time_offset, $expected_status ): void {
200200

201201
$post_id = self::factory()->post->create(
202202
array(
203203
'post_status' => $initial_status,
204204
)
205205
);
206206

207+
$initial_date_timestamp = strtotime( get_post( $post_id )->post_date );
208+
$initial_date_gmt_timestamp = strtotime( get_post( $post_id )->post_date_gmt );
209+
207210
$future_date = gmdate( 'Y-m-d H:i:s', strtotime( $time_offset ) );
208211
$update_data = array(
209212
'ID' => $post_id,
@@ -214,10 +217,19 @@ public function test_update_post_preserves_date_for_future_posts( $initial_statu
214217
wp_update_post( $update_data );
215218
$updated_post = get_post( $post_id );
216219

217-
$this->assertSame( $future_date, $updated_post->post_date_gmt, 'Post date should be updated accordingly.' );
220+
$updated_date_timestamp = strtotime( get_post( $post_id )->post_date );
221+
$updated_date_gmt_timestamp = strtotime( get_post( $post_id )->post_date_gmt );
222+
223+
if ( substr( $time_offset, 0, 1 ) === '+' ) {
224+
$this->assertGreaterThan( $initial_date_timestamp, $updated_date_timestamp, 'Post date should be in the future compared to initial date.' );
225+
$this->assertGreaterThan( $initial_date_gmt_timestamp, $updated_date_gmt_timestamp, 'Post date GMT should be in the future compared to initial date GMT.' );
226+
} else {
227+
$this->assertLessThan( $initial_date_timestamp, $updated_date_timestamp, 'Post date should be in the past compared to initial date.' );
228+
$this->assertLessThan( $initial_date_gmt_timestamp, $updated_date_gmt_timestamp, 'Post date GMT should be in the past compared to initial date GMT.' );
229+
}
230+
218231
$this->assertSame( $expected_status, $updated_post->post_status, "Post status should be '{$expected_status}' after update." );
219232
}
220-
221233
/**
222234
* Data provider for test_update_post_preserves_date_for_future_posts.
223235
*

0 commit comments

Comments
 (0)