Files
wordpress-develop/tests/phpunit/tests/comment/getCommentLink.php
T
Sergey Biryukov c70fe62ed1 Tests: Replace assertContains() with assertStringContainsString() when used with strings.
Using the `assertContains()` and `assertNotContains()` methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

* `assertStringContainsString()`
* `assertStringContainsStringIgnoringCase`
* `assertStringNotContainsString()`
* `assertStringNotContainsStringIgnoringCase`

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods were added to the `WP_UnitTestCase` class for PHPUnit < 7.5.

Follow-up to [51331], [51451], [51461].

Props jrf, dd32, SergeyBiryukov.
See #53363, #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51462 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-19 14:00:11 +00:00

148 lines
3.9 KiB
PHP

<?php
/**
* @group comment
*/
class Tests_Comment_GetCommentLink extends WP_UnitTestCase {
protected static $p;
protected static $comments = array();
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
$now = time();
self::$p = $factory->post->create();
self::$comments[] = $factory->comment->create(
array(
'comment_post_ID' => self::$p,
'comment_content' => '1',
'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', $now - 100 ),
)
);
self::$comments[] = $factory->comment->create(
array(
'comment_post_ID' => self::$p,
'comment_content' => '2',
'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', $now - 200 ),
)
);
self::$comments[] = $factory->comment->create(
array(
'comment_post_ID' => self::$p,
'comment_content' => '3',
'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', $now - 300 ),
)
);
self::$comments[] = $factory->comment->create(
array(
'comment_post_ID' => self::$p,
'comment_content' => '4',
'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', $now - 400 ),
)
);
self::$comments[] = $factory->comment->create(
array(
'comment_post_ID' => self::$p,
'comment_content' => '4',
'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', $now - 500 ),
)
);
self::$comments[] = $factory->comment->create(
array(
'comment_post_ID' => self::$p,
'comment_content' => '4',
'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', $now - 600 ),
)
);
}
/**
* @ticket 34068
*/
public function test_default_comments_page_newest_default_page_should_have_cpage() {
update_option( 'page_comments', 1 );
update_option( 'default_comments_page', 'newest' );
update_option( 'comments_per_page', 2 );
$found = get_comment_link( self::$comments[1] );
$this->assertStringContainsString( 'cpage=3', $found );
}
/**
* @ticket 34068
*/
public function test_default_comments_page_newest_middle_page_should_have_cpage() {
update_option( 'page_comments', 1 );
update_option( 'default_comments_page', 'newest' );
update_option( 'comments_per_page', 2 );
$found = get_comment_link( self::$comments[3] );
$this->assertStringContainsString( 'cpage=2', $found );
}
/**
* @ticket 34068
*/
public function test_default_comments_page_newest_last_page_should_have_cpage() {
update_option( 'page_comments', 1 );
update_option( 'default_comments_page', 'newest' );
update_option( 'comments_per_page', 2 );
$found = get_comment_link( self::$comments[5] );
$this->assertStringContainsString( 'cpage=1', $found );
}
/**
* @ticket 34068
*/
public function test_default_comments_page_oldest_default_page_should_not_have_cpage() {
update_option( 'default_comments_page', 'oldest' );
update_option( 'comments_per_page', 2 );
$found = get_comment_link( self::$comments[5] );
$this->assertStringNotContainsString( 'cpage', $found );
}
/**
* @ticket 34068
*/
public function test_default_comments_page_oldest_middle_page_should_have_cpage() {
update_option( 'page_comments', 1 );
update_option( 'default_comments_page', 'oldest' );
update_option( 'comments_per_page', 2 );
$found = get_comment_link( self::$comments[3] );
$this->assertStringContainsString( 'cpage=2', $found );
}
/**
* @ticket 34068
*/
public function test_default_comments_page_oldest_last_page_should_have_cpage() {
update_option( 'page_comments', 1 );
update_option( 'default_comments_page', 'oldest' );
update_option( 'comments_per_page', 2 );
$found = get_comment_link( self::$comments[1] );
$this->assertStringContainsString( 'cpage=3', $found );
}
/**
* @ticket 34946
*/
public function test_should_not_contain_comment_page_1_when_pagination_is_disabled() {
$this->set_permalink_structure( '/%postname%/' );
update_option( 'page_comments', 0 );
$found = get_comment_link( self::$comments[1] );
$this->assertStringNotContainsString( 'comment-page-1', $found );
}
}