wordpress-develop/tests/phpunit/tests/formatting/wpTrimExcerpt.php
Andrew Ozz 5a3f8484d6 Build/Test Tools, Formatting group:
- Add and update @covers tags.
- Add and improve docs and inline comments.

Props pbeane, hellofromTonya, antonvlasenko, ironprogrammer, SergeyBiryukov, costdev.
See #39265.

git-svn-id: https://develop.svn.wordpress.org/trunk@53562 602fd350-edb4-49c9-b593-d223f7449a82
2022-06-23 20:27:34 +00:00

96 lines
2.2 KiB
PHP

<?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() {
if ( PHP_VERSION_ID >= 80100 ) {
/*
* For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
* via hooked in filter functions until a more structural solution to the
* "missing input validation" conundrum has been architected and implemented.
*/
$this->expectDeprecation();
$this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
}
$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 ) );
}
}