postEmbedUrl.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @group oembed
  4. */
  5. class Tests_Post_Embed_URL extends WP_UnitTestCase {
  6. function test_non_existent_post() {
  7. $embed_url = get_post_embed_url( 0 );
  8. $this->assertFalse( $embed_url );
  9. }
  10. function test_with_pretty_permalinks() {
  11. $this->set_permalink_structure( '/%postname%' );
  12. $post_id = self::factory()->post->create();
  13. $permalink = get_permalink( $post_id );
  14. $embed_url = get_post_embed_url( $post_id );
  15. $this->assertSame( $permalink . '/embed', $embed_url );
  16. }
  17. function test_with_ugly_permalinks() {
  18. $post_id = self::factory()->post->create();
  19. $permalink = get_permalink( $post_id );
  20. $embed_url = get_post_embed_url( $post_id );
  21. $this->assertSame( $permalink . '&embed=true', $embed_url );
  22. }
  23. /**
  24. * @ticket 34971
  25. */
  26. function test_static_front_page() {
  27. $this->set_permalink_structure( '/%postname%/' );
  28. $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
  29. update_option( 'show_on_front', 'page' );
  30. update_option( 'page_on_front', $post_id );
  31. $embed_url = get_post_embed_url( $post_id );
  32. $this->assertSame( user_trailingslashit( trailingslashit( home_url() ) . 'embed' ), $embed_url );
  33. update_option( 'show_on_front', 'posts' );
  34. }
  35. /**
  36. * @ticket 34971
  37. */
  38. function test_static_front_page_with_ugly_permalinks() {
  39. $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
  40. update_option( 'show_on_front', 'page' );
  41. update_option( 'page_on_front', $post_id );
  42. $embed_url = get_post_embed_url( $post_id );
  43. $this->assertSame( trailingslashit( home_url() ) . '?embed=true', $embed_url );
  44. update_option( 'show_on_front', 'posts' );
  45. }
  46. /**
  47. * @ticket 34971
  48. */
  49. function test_page_conflicts_with_embed_slug() {
  50. $this->set_permalink_structure( '/%postname%/' );
  51. $parent_page = self::factory()->post->create( array( 'post_type' => 'page' ) );
  52. add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
  53. $child_page = self::factory()->post->create(
  54. array(
  55. 'post_type' => 'page',
  56. 'post_parent' => $parent_page,
  57. 'post_name' => 'embed',
  58. )
  59. );
  60. remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
  61. $this->assertSame( get_permalink( $parent_page ) . '?embed=true', get_post_embed_url( $parent_page ) );
  62. $this->assertSame( get_permalink( $child_page ) . 'embed/', get_post_embed_url( $child_page ) );
  63. }
  64. /**
  65. * @ticket 34971
  66. */
  67. function test_static_front_page_conflicts_with_embed_slug() {
  68. $this->set_permalink_structure( '/%postname%/' );
  69. // Create a post with the 'embed' post_name.
  70. add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
  71. $post_embed_slug = self::factory()->post->create( array( 'post_name' => 'embed' ) );
  72. remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
  73. $page_front = self::factory()->post->create( array( 'post_type' => 'page' ) );
  74. update_option( 'show_on_front', 'page' );
  75. update_option( 'page_on_front', $page_front );
  76. $this->assertSame( home_url() . '/embed/embed/', get_post_embed_url( $post_embed_slug ) );
  77. $this->assertSame( home_url() . '/?embed=true', get_post_embed_url( $page_front ) );
  78. update_option( 'show_on_front', 'posts' );
  79. }
  80. public function filter_unique_post_slug() {
  81. return 'embed';
  82. }
  83. }