getTheContent.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @group post
  4. * @group formatting
  5. */
  6. class Tests_Post_GetTheContent extends WP_UnitTestCase {
  7. /**
  8. * @ticket 42814
  9. */
  10. public function test_argument_back_compat_more_link_text() {
  11. $text = 'Foo<!--more-->Bar';
  12. $p = self::factory()->post->create( array( 'post_content' => $text ) );
  13. $q = new WP_Query( array( 'p' => $p ) );
  14. while ( $q->have_posts() ) {
  15. $q->the_post();
  16. $found = get_the_content( 'Ping' );
  17. }
  18. $this->assertContains( '>Ping<', $found );
  19. }
  20. /**
  21. * @ticket 42814
  22. */
  23. public function test_argument_back_compat_strip_teaser() {
  24. $text = 'Foo<!--more-->Bar';
  25. $p = self::factory()->post->create( array( 'post_content' => $text ) );
  26. $this->go_to( get_permalink( $p ) );
  27. $q = new WP_Query( array( 'p' => $p ) );
  28. while ( $q->have_posts() ) {
  29. $q->the_post();
  30. $found = get_the_content( null, true );
  31. }
  32. $this->assertNotContains( 'Foo', $found );
  33. }
  34. /**
  35. * @ticket 42814
  36. */
  37. public function test_content_other_post() {
  38. $text_1 = 'Foo<!--nextpage-->Bar<!--nextpage-->Baz';
  39. $post_1 = self::factory()->post->create_and_get( array( 'post_content' => $text_1 ) );
  40. $text_2 = 'Bing<!--nextpage-->Bang<!--nextpage-->Boom';
  41. $post_2 = self::factory()->post->create_and_get( array( 'post_content' => $text_2 ) );
  42. setup_postdata( $post_1 );
  43. $found = get_the_content( null, true, $post_2 );
  44. $this->assertSame( 'Bing', $found );
  45. }
  46. /**
  47. * @ticket 42814
  48. */
  49. public function test_should_respect_pagination_of_inner_post() {
  50. $text_1 = 'Foo<!--nextpage-->Bar<!--nextpage-->Baz';
  51. $post_1 = self::factory()->post->create_and_get( array( 'post_content' => $text_1 ) );
  52. $text_2 = 'Bing<!--nextpage-->Bang<!--nextpage-->Boom';
  53. $post_2 = self::factory()->post->create_and_get( array( 'post_content' => $text_2 ) );
  54. $go_to = add_query_arg( 'page', '2', get_permalink( $post_1->ID ) );
  55. $this->go_to( $go_to );
  56. while ( have_posts() ) {
  57. the_post();
  58. $found = get_the_content( '', false, $post_2 );
  59. }
  60. $this->assertSame( 'Bang', $found );
  61. }
  62. /**
  63. * @ticket 47824
  64. */
  65. public function test_should_fall_back_to_post_global_outside_of_the_loop() {
  66. $GLOBALS['post'] = self::factory()->post->create( array( 'post_content' => 'Foo' ) );
  67. $this->assertSame( 'Foo', get_the_content() );
  68. }
  69. }