Make WordPress Core

Ticket #41846: 41846-2.diff

File 41846-2.diff, 1.3 KB (added by birgire, 6 years ago)
  • src/wp-includes/comment-template.php

    diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php
    index b10fe14..69dcc16 100644
    function get_comment_reply_link( $args = array(), $comment = null, $post = null 
    16461646
    16471647        $comment = get_comment( $comment );
    16481648
     1649        if ( empty( $comment ) ) {
     1650                return;
     1651        }
     1652
    16491653        if ( empty( $post ) ) {
    16501654                $post = $comment->comment_post_ID;
    16511655        }
  • tests/phpunit/tests/comment/getCommentReplyLink.php

    diff --git tests/phpunit/tests/comment/getCommentReplyLink.php tests/phpunit/tests/comment/getCommentReplyLink.php
    index 5ca395e..73e2885 100644
    class Tests_Comment_GetCommentReplyLink extends WP_UnitTestCase { 
    6666
    6767                $this->assertContains( $expected_url, $comment_reply_link );
    6868        }
     69
     70        /**
     71         * @ticket 41846
     72         */
     73        public function test_should_return_null_when_depth_less_than_max_depth_and_comment_null_and_no_current_global_comment() {
     74
     75                // Let max depth be greater than depth and depth be non-zero.
     76                $args = array(
     77                        'depth'     => 1,
     78                        'max_depth' => 2,
     79                );
     80
     81                // Make sure there's no global comment object.
     82                add_filter( 'get_comment', '__return_null' );
     83
     84                $actual = get_comment_reply_link( $args );
     85
     86                $this->assertNull( $actual );
     87        }
     88
    6989}