mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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
90 lines
1.8 KiB
PHP
90 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group comment
|
|
*/
|
|
class Tests_Comment_GetCommentReplyLink extends WP_UnitTestCase {
|
|
/**
|
|
* @ticket 38170
|
|
*/
|
|
public function test_should_return_null_when_max_depth_is_less_than_depth() {
|
|
$args = array(
|
|
'depth' => 5,
|
|
'max_depth' => 4,
|
|
);
|
|
|
|
$this->assertNull( get_comment_reply_link( $args ) );
|
|
}
|
|
|
|
/**
|
|
* @ticket 38170
|
|
*/
|
|
public function test_should_return_null_when_default_max_depth_is_less_than_depth() {
|
|
$args = array(
|
|
'depth' => 5,
|
|
);
|
|
|
|
$this->assertNull( get_comment_reply_link( $args ) );
|
|
}
|
|
|
|
/**
|
|
* Ensure comment reply links include post permalink.
|
|
*
|
|
* @ticket 47174
|
|
*/
|
|
public function test_get_comment_reply_link_should_include_post_permalink() {
|
|
// Create a sample post.
|
|
$post_id = self::factory()->post->create();
|
|
|
|
// Insert comment.
|
|
$comment_id = self::factory()->comment->create(
|
|
array(
|
|
'comment_post_ID' => $post_id,
|
|
'user_id' => 1,
|
|
)
|
|
);
|
|
|
|
// `depth` and `max_depth` required for reply links to display.
|
|
$comment_reply_link = get_comment_reply_link(
|
|
array(
|
|
'depth' => 1,
|
|
'max_depth' => 5,
|
|
),
|
|
$comment_id,
|
|
$post_id
|
|
);
|
|
|
|
$expected_url = esc_url(
|
|
add_query_arg(
|
|
array(
|
|
'p' => $post_id,
|
|
'replytocom' => $comment_id,
|
|
),
|
|
home_url( '/#respond' )
|
|
)
|
|
);
|
|
|
|
$this->assertStringContainsString( $expected_url, $comment_reply_link );
|
|
}
|
|
|
|
/**
|
|
* @ticket 41846
|
|
*/
|
|
public function test_should_return_null_when_depth_less_than_max_depth_and_comment_null_and_no_current_global_comment() {
|
|
|
|
// Let max depth be greater than depth and depth be non-zero.
|
|
$args = array(
|
|
'depth' => 1,
|
|
'max_depth' => 2,
|
|
);
|
|
|
|
// Make sure there's no global comment object.
|
|
add_filter( 'get_comment', '__return_null' );
|
|
|
|
$actual = get_comment_reply_link( $args );
|
|
|
|
$this->assertNull( $actual );
|
|
}
|
|
|
|
}
|