| | 455 | |
| | 456 | /** |
| | 457 | * @ticket 33045 |
| | 458 | */ |
| | 459 | public function test_get_parent_post() { |
| | 460 | $post = array( |
| | 461 | 'post_status' => 'publish', |
| | 462 | 'post_content' => rand_str(), |
| | 463 | 'post_title' => rand_str(), |
| | 464 | 'post_type' => 'page', |
| | 465 | ); |
| | 466 | |
| | 467 | // Insert two initial posts. |
| | 468 | $id_parent = wp_insert_post( $post ); |
| | 469 | $id_child = wp_insert_post( $post ); |
| | 470 | |
| | 471 | // Test if child get_parent_post() post returns Null by default. |
| | 472 | $parent = get_parent_post( $id_child ); |
| | 473 | $this->assertNull( $parent ); |
| | 474 | |
| | 475 | // Update child post with a parent. |
| | 476 | wp_update_post( |
| | 477 | array( |
| | 478 | 'ID' => $id_child, |
| | 479 | 'post_parent' => $id_parent, |
| | 480 | ) |
| | 481 | ); |
| | 482 | |
| | 483 | // Test if child get_parent_post() post returns the parent object. |
| | 484 | $parent = get_parent_post( $id_child ); |
| | 485 | $this->assertSame( $id_parent, $parent->ID ); |
| | 486 | } |
| | 487 | |
| | 488 | /** |
| | 489 | * @ticket 33045 |
| | 490 | */ |
| | 491 | public function test_has_parent_post() { |
| | 492 | $post = array( |
| | 493 | 'post_status' => 'publish', |
| | 494 | 'post_content' => rand_str(), |
| | 495 | 'post_title' => rand_str(), |
| | 496 | 'post_type' => 'page', |
| | 497 | ); |
| | 498 | |
| | 499 | // Insert two initial posts. |
| | 500 | $id_parent = wp_insert_post( $post ); |
| | 501 | $id_child = wp_insert_post( $post ); |
| | 502 | |
| | 503 | // Test if child has_parent_post() post returns False by default. |
| | 504 | $parent = has_parent_post( $id_child ); |
| | 505 | $this->assertFalse( $parent ); |
| | 506 | |
| | 507 | // Update child post with a parent. |
| | 508 | wp_update_post( |
| | 509 | array( |
| | 510 | 'ID' => $id_child, |
| | 511 | 'post_parent' => $id_parent, |
| | 512 | ) |
| | 513 | ); |
| | 514 | |
| | 515 | // Test if child has_parent_post() returns True. |
| | 516 | $parent = has_parent_post( $id_child ); |
| | 517 | $this->assertTrue( $parent ); |
| | 518 | } |