getPageUri.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @group post
  4. */
  5. class Tests_Post_GetPageUri extends WP_UnitTestCase {
  6. /**
  7. * @ticket 22883
  8. */
  9. function test_get_page_uri_with_stdclass_post_object() {
  10. $post_id = self::factory()->post->create( array( 'post_name' => 'get-page-uri-post-name' ) );
  11. // Mimick an old stdClass post object, missing the ancestors field.
  12. $post_array = (object) get_post( $post_id, ARRAY_A );
  13. unset( $post_array->ancestors );
  14. // Dummy assertion. If this test fails, it will actually error out on an E_WARNING.
  15. $this->assertSame( 'get-page-uri-post-name', get_page_uri( $post_array ) );
  16. }
  17. /**
  18. * @ticket 24491
  19. */
  20. function test_get_page_uri_with_nonexistent_post() {
  21. global $wpdb;
  22. $post_id = $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" ) + 1;
  23. $this->assertFalse( get_page_uri( $post_id ) );
  24. }
  25. /**
  26. * @ticket 15963
  27. */
  28. function test_get_post_uri_check_orphan() {
  29. $parent_id = self::factory()->post->create( array( 'post_name' => 'parent' ) );
  30. $child_id = self::factory()->post->create(
  31. array(
  32. 'post_name' => 'child',
  33. 'post_parent' => $parent_id,
  34. )
  35. );
  36. // Check the parent for good measure.
  37. $this->assertSame( 'parent', get_page_uri( $parent_id ) );
  38. // Try the child normally.
  39. $this->assertSame( 'parent/child', get_page_uri( $child_id ) );
  40. // Now delete the parent from the database and check.
  41. wp_delete_post( $parent_id, true );
  42. $this->assertSame( 'child', get_page_uri( $child_id ) );
  43. }
  44. /**
  45. * @ticket 36174
  46. */
  47. function test_get_page_uri_with_a_draft_parent_with_empty_slug() {
  48. $parent_id = self::factory()->post->create( array( 'post_name' => 'parent' ) );
  49. $child_id = self::factory()->post->create(
  50. array(
  51. 'post_name' => 'child',
  52. 'post_parent' => $parent_id,
  53. )
  54. );
  55. wp_update_post(
  56. array(
  57. 'ID' => $parent_id,
  58. 'post_name' => '',
  59. 'post_status' => 'draft',
  60. )
  61. );
  62. $this->assertSame( 'child', get_page_uri( $child_id ) );
  63. }
  64. /**
  65. * @ticket 26284
  66. */
  67. function test_get_page_uri_without_argument() {
  68. $post_id = self::factory()->post->create(
  69. array(
  70. 'post_title' => 'Blood Orange announces summer tour dates',
  71. 'post_name' => 'blood-orange-announces-summer-tour-dates',
  72. )
  73. );
  74. $post = get_post( $post_id );
  75. $this->go_to( get_permalink( $post_id ) );
  76. $this->assertSame( 'blood-orange-announces-summer-tour-dates', get_page_uri() );
  77. }
  78. }