WpTrimExcerpt.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @group formatting
  4. * @covers ::wp_trim_excerpt
  5. */
  6. class Tests_Formatting_WpTrimExcerpt extends WP_UnitTestCase {
  7. /**
  8. * @ticket 25349
  9. */
  10. public function test_secondary_loop_respect_more() {
  11. $post1 = self::factory()->post->create(
  12. array(
  13. 'post_content' => 'Post 1 Page 1<!--more-->Post 1 Page 2',
  14. )
  15. );
  16. $post2 = self::factory()->post->create(
  17. array(
  18. 'post_content' => 'Post 2 Page 1<!--more-->Post 2 Page 2',
  19. )
  20. );
  21. $this->go_to( '/?p=' . $post1 );
  22. setup_postdata( get_post( $post1 ) );
  23. $q = new WP_Query(
  24. array(
  25. 'post__in' => array( $post2 ),
  26. )
  27. );
  28. if ( $q->have_posts() ) {
  29. while ( $q->have_posts() ) {
  30. $q->the_post();
  31. $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() );
  32. }
  33. }
  34. }
  35. /**
  36. * @ticket 25349
  37. */
  38. public function test_secondary_loop_respect_nextpage() {
  39. $post1 = self::factory()->post->create(
  40. array(
  41. 'post_content' => 'Post 1 Page 1<!--nextpage-->Post 1 Page 2',
  42. )
  43. );
  44. $post2 = self::factory()->post->create(
  45. array(
  46. 'post_content' => 'Post 2 Page 1<!--nextpage-->Post 2 Page 2',
  47. )
  48. );
  49. $this->go_to( '/?p=' . $post1 );
  50. setup_postdata( get_post( $post1 ) );
  51. $q = new WP_Query(
  52. array(
  53. 'post__in' => array( $post2 ),
  54. )
  55. );
  56. if ( $q->have_posts() ) {
  57. while ( $q->have_posts() ) {
  58. $q->the_post();
  59. $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() );
  60. }
  61. }
  62. }
  63. /**
  64. * @ticket 51042
  65. */
  66. public function test_should_generate_excerpt_for_empty_values() {
  67. $post = self::factory()->post->create(
  68. array(
  69. 'post_content' => 'Post content',
  70. )
  71. );
  72. $this->assertSame( 'Post content', wp_trim_excerpt( '', $post ) );
  73. $this->assertSame( 'Post content', wp_trim_excerpt( null, $post ) );
  74. $this->assertSame( 'Post content', wp_trim_excerpt( false, $post ) );
  75. }
  76. }