123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /**
- * @group formatting
- * @covers ::wp_trim_excerpt
- */
- class Tests_Formatting_WpTrimExcerpt extends WP_UnitTestCase {
- /**
- * @ticket 25349
- */
- public function test_secondary_loop_respect_more() {
- $post1 = self::factory()->post->create(
- array(
- 'post_content' => 'Post 1 Page 1<!--more-->Post 1 Page 2',
- )
- );
- $post2 = self::factory()->post->create(
- array(
- 'post_content' => 'Post 2 Page 1<!--more-->Post 2 Page 2',
- )
- );
- $this->go_to( '/?p=' . $post1 );
- setup_postdata( get_post( $post1 ) );
- $q = new WP_Query(
- array(
- 'post__in' => array( $post2 ),
- )
- );
- if ( $q->have_posts() ) {
- while ( $q->have_posts() ) {
- $q->the_post();
- $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() );
- }
- }
- }
- /**
- * @ticket 25349
- */
- public function test_secondary_loop_respect_nextpage() {
- $post1 = self::factory()->post->create(
- array(
- 'post_content' => 'Post 1 Page 1<!--nextpage-->Post 1 Page 2',
- )
- );
- $post2 = self::factory()->post->create(
- array(
- 'post_content' => 'Post 2 Page 1<!--nextpage-->Post 2 Page 2',
- )
- );
- $this->go_to( '/?p=' . $post1 );
- setup_postdata( get_post( $post1 ) );
- $q = new WP_Query(
- array(
- 'post__in' => array( $post2 ),
- )
- );
- if ( $q->have_posts() ) {
- while ( $q->have_posts() ) {
- $q->the_post();
- $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() );
- }
- }
- }
- /**
- * @ticket 51042
- */
- public function test_should_generate_excerpt_for_empty_values() {
- $post = self::factory()->post->create(
- array(
- 'post_content' => 'Post content',
- )
- );
- $this->assertSame( 'Post content', wp_trim_excerpt( '', $post ) );
- $this->assertSame( 'Post content', wp_trim_excerpt( null, $post ) );
- $this->assertSame( 'Post content', wp_trim_excerpt( false, $post ) );
- }
- }
|