Comments: Don't output "cancel comment reply link" if comments aren't threaded.

Though hidden via `style="display:none;"`, if the comments aren't threaded, this commit doesn't output the cancel comment reply link (skips over that logic). Change in `comment_form()`.

Adds tests.

Follow-up to [12810], [38959].

Props henrywright, jigneshnakrani, rachelbaker, desrosj, audrasjb, hellofromTonya.
Fixes #37267.

git-svn-id: https://develop.svn.wordpress.org/trunk@52175 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork
2021-11-16 02:13:25 +00:00
parent e265334aed
commit 32225077fc
2 changed files with 35 additions and 4 deletions
+30 -1
View File
@@ -1,9 +1,16 @@
<?php
/**
* @group comment
* @group comment
* @covers ::comment_form
*/
class Tests_Comment_CommentForm extends WP_UnitTestCase {
public static $post_id;
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$post_id = $factory->post->create();
}
public function test_default_markup_for_submit_button_and_wrapper() {
$p = self::factory()->post->create();
@@ -123,4 +130,26 @@ class Tests_Comment_CommentForm extends WP_UnitTestCase {
$this->assertStringNotContainsString( 'aria-describedby="email-notes"', $form_without_aria );
}
/**
* @ticket 32767
*/
public function test_when_thread_comments_enabled() {
update_option( 'thread_comments', true );
$form = get_echo( 'comment_form', array( array(), self::$post_id ) );
$expected = '<a rel="nofollow" id="cancel-comment-reply-link" href="#respond" style="display:none;">Cancel reply</a>';
$this->assertStringContainsString( $expected, $form );
}
/**
* @ticket 32767
*/
public function test_when_thread_comments_disabled() {
delete_option( 'thread_comments' );
$form = get_echo( 'comment_form', array( array(), self::$post_id ) );
$expected = '<a rel="nofollow" id="cancel-comment-reply-link" href="#respond" style="display:none;">Cancel reply</a>';
$this->assertStringNotContainsString( $expected, $form );
}
}