@@ -45,7 +45,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
4545 global $ wp_rewrite ;
4646
4747 $ wp_rewrite ->init ();
48- $ wp_rewrite ->set_permalink_structure ( '/%year%/%monthnum%/%day%/% postname%/ ' );
48+ $ wp_rewrite ->set_permalink_structure ( '/%year%/%postname%/ ' );
4949 $ wp_rewrite ->flush_rules ();
5050
5151 $ statuses = array ( 'publish ' , 'draft ' , 'pending ' , 'private ' );
@@ -54,6 +54,8 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
5454 array (
5555 'post_status ' => $ status ,
5656 'post_title ' => 'Test Post ' . ucfirst ( $ status ),
57+ 'post_name ' => 'test-post- ' . $ status ,
58+ 'post_date ' => '2025-06-01 12:00:00 ' , // Set date for predictable URLs.
5759 )
5860 );
5961 self ::$ post_ids [ $ status ] = $ post_id ;
@@ -65,7 +67,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
6567 */
6668 public function set_up () {
6769 parent ::set_up ();
68- $ this ->set_permalink_structure ( '/%year%/%monthnum%/%day%/% postname%/ ' );
70+ $ this ->set_permalink_structure ( '/%year%/%postname%/ ' );
6971 $ this ->pings = array ();
7072 add_filter ( 'pre_http_request ' , array ( $ this , 'mocked_ping_response ' ), 10 , 3 );
7173 }
@@ -132,10 +134,12 @@ public function test_ping_on_post_publish() {
132134 array (
133135 'post_status ' => 'publish ' ,
134136 'post_title ' => 'Test Post ' ,
137+ 'post_name ' => 'ping-on-post-publish ' ,
138+ 'post_date ' => '2025-06-01 12:00:00 ' , // Set date for predictable URLs.
135139 )
136140 );
137141
138- $ this ->assertPing ( get_permalink ( $ post_id ), 'Ping should include the post URL on publish. ' );
142+ $ this ->assertPing ( home_url ( ' /2025/ping-on-post-publish/ ' ), 'Ping should include the post URL on publish. ' );
139143 }
140144
141145 /**
@@ -151,20 +155,18 @@ public function test_ping_on_post_update() {
151155 )
152156 );
153157
154- $ this ->assertPing ( get_permalink ( $ post_id ), 'Ping should include the post URL on update. ' );
158+ $ this ->assertPing ( home_url ( ' /2025/test-post-publish/ ' ), 'Ping should include the post URL on update. ' );
155159 }
156160
157161 /**
158162 * Ensure trashing a previously published post pings the old URL.
159163 */
160164 public function test_ping_on_post_trash () {
161165 $ post_id = self ::$ post_ids ['publish ' ];
162- $ original_permalink = get_permalink ( $ post_id );
163166
164167 wp_trash_post ( $ post_id );
165- $ trashed_permalink = get_permalink ( $ post_id );
166168
167- $ this ->assertPing ( $ original_permalink , 'Ping should include the post URL on trash. ' );
168- $ this ->assertNotPing ( $ trashed_permalink , 'Ping should not include the trashed post URL. ' );
169+ $ this ->assertPing ( home_url ( ' /2025/test-post-publish/ ' ) , 'Ping should include the post URL on trash. ' );
170+ $ this ->assertNotPing ( home_url ( " /?p= { $ post_id }" ) , 'Ping should not include the trashed post URL. ' );
169171 }
170172}
0 commit comments