|
7 | 7 |
|
8 | 8 | namespace PWCC\SimpleSearchSubmission\Tests; |
9 | 9 |
|
| 10 | +use PWCC\SimpleSearchSubmission; |
10 | 11 | use WP_UnitTestCase; |
11 | 12 | use WP_UnitTest_Factory; |
12 | 13 |
|
@@ -242,4 +243,84 @@ public function test_no_ping_on_custom_private_post_status() { |
242 | 243 | unset( $wp_post_statuses['custom_private'] ); |
243 | 244 | $this->assertNotPing( get_permalink( $post_id ), 'Custom private post status should not ping.' ); |
244 | 245 | } |
| 246 | + |
| 247 | + /** |
| 248 | + * Ensure de-indexed urls are pinged once only. |
| 249 | + */ |
| 250 | + public function test_no_duplicate_pings_on_deindexed_url() { |
| 251 | + $post_id = self::$post_ids['publish']; |
| 252 | + |
| 253 | + // Update the post slug. |
| 254 | + wp_update_post( |
| 255 | + array( |
| 256 | + 'ID' => $post_id, |
| 257 | + 'post_name' => 'updated-test-post-publish', |
| 258 | + ) |
| 259 | + ); |
| 260 | + |
| 261 | + // Ensure both old and new URLs are pinged. |
| 262 | + $this->assertPing( home_url( '/2025/test-post-publish/' ), 'Ping should include the old post URL after slug change.' ); |
| 263 | + $this->assertPing( home_url( '/2025/updated-test-post-publish/' ), 'Ping should include the new post URL after slug change.' ); |
| 264 | + // Ensure last ping URL is the updated URL. |
| 265 | + $last_ping_url = SimpleSearchSubmission\get_last_post_ping_url( $post_id ); |
| 266 | + $this->assertSame( home_url( '/2025/updated-test-post-publish/' ), $last_ping_url, 'Last ping URL should be the updated URL.' ); |
| 267 | + |
| 268 | + // Clear the ping list. |
| 269 | + $this->pings = array(); |
| 270 | + |
| 271 | + // Update the post content. |
| 272 | + wp_update_post( |
| 273 | + array( |
| 274 | + 'ID' => $post_id, |
| 275 | + 'post_content' => 'Another update to Test Post', |
| 276 | + ) |
| 277 | + ); |
| 278 | + |
| 279 | + // Ensure only the new URL is pinged again. |
| 280 | + $this->assertNotPing( home_url( '/2025/test-post-publish/' ), 'Old post URL should not be pinged again after content update.' ); |
| 281 | + $this->assertPing( home_url( '/2025/updated-test-post-publish/' ), 'New post URL should be pinged again after content update.' ); |
| 282 | + // Ensure last ping URL is the updated URL. |
| 283 | + $last_ping_url = SimpleSearchSubmission\get_last_post_ping_url( $post_id ); |
| 284 | + $this->assertSame( home_url( '/2025/updated-test-post-publish/' ), $last_ping_url, 'Last ping URL should be the updated URL after the second ping.' ); |
| 285 | + } |
| 286 | + |
| 287 | + /** |
| 288 | + * Ensure updating the pinged URLs lists appends the new URLs correctly. |
| 289 | + */ |
| 290 | + public function test_update_post_ping_urls_appends_correctly() { |
| 291 | + $post_id = self::$post_ids['publish']; |
| 292 | + |
| 293 | + // Update the post slug for the first time. |
| 294 | + wp_update_post( |
| 295 | + array( |
| 296 | + 'ID' => $post_id, |
| 297 | + 'post_name' => 'first-update-test-post-publish', |
| 298 | + ) |
| 299 | + ); |
| 300 | + |
| 301 | + $last_ping_url = SimpleSearchSubmission\get_last_post_ping_url( $post_id ); |
| 302 | + $this->assertSame( home_url( '/2025/first-update-test-post-publish/' ), $last_ping_url, 'Last ping URL should be the first updated URL.' ); |
| 303 | + |
| 304 | + // Update the post slug for the second time. |
| 305 | + wp_update_post( |
| 306 | + array( |
| 307 | + 'ID' => $post_id, |
| 308 | + 'post_name' => 'second-update-test-post-publish', |
| 309 | + ) |
| 310 | + ); |
| 311 | + |
| 312 | + $last_ping_url = SimpleSearchSubmission\get_last_post_ping_url( $post_id ); |
| 313 | + $this->assertSame( home_url( '/2025/second-update-test-post-publish/' ), $last_ping_url, 'Last ping URL should be the second updated URL.' ); |
| 314 | + |
| 315 | + // Restore the first updated URL. |
| 316 | + wp_update_post( |
| 317 | + array( |
| 318 | + 'ID' => $post_id, |
| 319 | + 'post_name' => 'first-update-test-post-publish', |
| 320 | + ) |
| 321 | + ); |
| 322 | + |
| 323 | + $last_ping_url = SimpleSearchSubmission\get_last_post_ping_url( $post_id ); |
| 324 | + $this->assertSame( home_url( '/2025/first-update-test-post-publish/' ), $last_ping_url, 'Last ping URL should be the restored first updated URL.' ); |
| 325 | + } |
245 | 326 | } |
0 commit comments