Make WordPress Core

Ticket #41846: 41846.diff

File 41846.diff, 1.4 KB (added by earnjam, 7 years ago)
  • src/wp-includes/comment-template.php

    diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php
    index ca0a8de714..6ddca706bb 100644
    function get_comment_reply_link( $args = array(), $comment = null, $post = null 
    16411641
    16421642        $comment = get_comment( $comment );
    16431643
     1644        if ( empty( $comment ) ) {
     1645                return;
     1646        }
     1647
    16441648        if ( empty( $post ) ) {
    16451649                $post = $comment->comment_post_ID;
    16461650        }
  • tests/phpunit/tests/comment/getCommentReplyLink.php

    diff --git tests/phpunit/tests/comment/getCommentReplyLink.php tests/phpunit/tests/comment/getCommentReplyLink.php
    index a9645fc4aa..a474077f7f 100644
    class Tests_Comment_GetCommentReplyLink extends WP_UnitTestCase { 
    2626
    2727                $this->assertNull( get_comment_reply_link( $args ) );
    2828        }
     29
     30        /**
     31         * @ticket 41846
     32         */
     33        public function test_should_return_null_when_depth_less_than_max_depth_and_comment_null_and_no_current_global_comment() {
     34
     35                $args = array(
     36                        'depth'     => 1,
     37                        'max_depth' => 2,
     38                );
     39
     40                $comment = null;
     41
     42                // store current global comment
     43                $tmp = $GLOBALS['comment'];
     44
     45                // remove global current comment
     46                unset( $GLOBALS['comment'] );
     47
     48                $this->assertFalse( isset( $GLOBALS['comment'] ) );
     49                                $this->assertNull( get_comment_reply_link( $args ), $comment );
     50
     51                // restore current global comment
     52                $GLOBALS['comment'] = $tmp;
     53        }
     54
    2955}