Ticket #36571: 36571.5.diff
File 36571.5.diff, 5.8 KB (added by , 7 years ago) |
---|
-
src/wp-includes/comment-template.php
diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php index 967778a..3f177bd 100644
function comment_author_email( $comment_ID = 0 ) { 138 138 * address and use it for their own means good and bad. 139 139 * 140 140 * @since 0.71 141 * @since 4.6.0 The `$comment` parameter was added. 141 142 * 142 143 * @param string $linktext Optional. Text to display instead of the comment author's email address. 143 144 * Default empty. 144 145 * @param string $before Optional. Text or HTML to display before the email link. Default empty. 145 146 * @param string $after Optional. Text or HTML to display after the email link. Default empty. 147 * @param int|WP_Comment $comment Optional. Comment ID or WP_Comment object. Default is the current comment. 146 148 */ 147 function comment_author_email_link( $linktext = '', $before = '', $after = '' ) {148 if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )149 function comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) { 150 if ( $link = get_comment_author_email_link( $linktext, $before, $after, $comment ) ) { 149 151 echo $link; 152 } 150 153 } 151 154 152 155 /** … … function comment_author_email_link( $linktext = '', $before = '', $after = '' ) 159 162 * address and use it for their own means good and bad. 160 163 * 161 164 * @since 2.7.0 165 * @since 4.6.0 The `$comment` parameter was added. 162 166 * 163 167 * @param string $linktext Optional. Text to display instead of the comment author's email address. 164 168 * Default empty. 165 169 * @param string $before Optional. Text or HTML to display before the email link. Default empty. 166 170 * @param string $after Optional. Text or HTML to display after the email link. Default empty. 171 * @param int|WP_Comment $comment Optional. Comment ID or WP_Comment object. Default is the current comment. 167 172 * @return string 168 173 */ 169 function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) { 170 $comment = get_comment(); 174 function get_comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) { 175 $comment = get_comment( $comment ); 176 171 177 /** 172 178 * Filter the comment author's email for display. 173 179 * … … function get_comment_author_email_link( $linktext = '', $before = '', $after = ' 181 187 * @param WP_Comment $comment The comment object. 182 188 */ 183 189 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment ); 190 184 191 if ((!empty($email)) && ($email != '@')) { 185 192 $display = ($linktext != '') ? $linktext : $email; 186 193 $return = $before; -
new file tests/phpunit/tests/comment/getCommentAuthorEmailLink.php
diff --git tests/phpunit/tests/comment/getCommentAuthorEmailLink.php tests/phpunit/tests/comment/getCommentAuthorEmailLink.php new file mode 100644 index 0000000..82a7307
- + 1 <?php 2 /** 3 * @group comment 4 */ 5 class Tests_Comment_GetCommentAuthorEmailLink extends WP_UnitTestCase { 6 public static $comment; 7 8 public function setUp() { 9 parent::setUp(); 10 11 // Fake the 'comment' global. 12 $GLOBALS['comment'] = self::$comment; 13 14 // Remove obfuscation for testing purposes. 15 remove_filter( 'comment_email', 'antispambot' ); 16 } 17 18 public function tearDown() { 19 unset( $GLOBALS['comment'] ); 20 parent::tearDown(); 21 22 add_filter( 'comment_email', 'antispambot' ); 23 } 24 25 public static function wpSetUpBeforeClass( $factory ) { 26 self::$comment = $factory->comment->create_and_get( array( 27 'comment_author_email' => 'foo@example.org' 28 ) ); 29 } 30 31 public static function wpTearDownAfterClass() { 32 wp_delete_comment( self::$comment->comment_ID, true ); 33 } 34 35 public function test_global_comment_with_default_parameters() { 36 $expected = '<a href="mailto:foo@example.org">foo@example.org</a>'; 37 38 $this->assertEquals( $expected, get_comment_author_email_link() ); 39 } 40 41 /** 42 * @ticket 36571 43 */ 44 public function test_all_parameters() { 45 unset( $GLOBALS['comment'] ); 46 47 $linktext = rand_str( 10 ); 48 $before = rand_str( 5 ); 49 $after = rand_str( 6 ); 50 $comment = self::factory()->comment->create_and_get( array( 51 'comment_author_email' => $email = 'baz@example.org' 52 ) ); 53 54 $expected = sprintf( '%1$s<a href="mailto:%2$s">%3$s</a>%4$s', $before, $email, $linktext, $after ); 55 56 $this->assertEquals( $expected, get_comment_author_email_link( $linktext, $before, $after, $comment ) ); 57 } 58 59 public function test_all_parameters_with_global_comment() { 60 $linktext = rand_str( 10 ); 61 $before = rand_str( 5 ); 62 $after = rand_str( 6 ); 63 64 $expected = sprintf( '%1$s<a href="mailto:foo@example.org">%2$s</a>%3$s', $before, $linktext, $after ); 65 66 $this->assertEquals( $expected, get_comment_author_email_link( $linktext, $before, $after ) ); 67 } 68 69 public function test_linktext() { 70 $expected = sprintf( '<a href="mailto:foo@example.org">%1$s</a>', $linktext = rand_str( 12 ) ); 71 72 $this->assertEquals( $expected, get_comment_author_email_link( $linktext ) ); 73 } 74 75 public function test_before() { 76 $expected = sprintf( '%1$s<a href="mailto:foo@example.org">foo@example.org</a>', $before = rand_str( 5 ) ); 77 78 $this->assertEquals( $expected, get_comment_author_email_link( '', $before ) ); 79 } 80 81 public function test_after() { 82 $expected = sprintf( '<a href="mailto:foo@example.org">foo@example.org</a>%1$s', $after = rand_str( 5 ) ); 83 84 $this->assertEquals( $expected, get_comment_author_email_link( '', '', $after ) ); 85 } 86 87 /** 88 * @ticket 36571 89 */ 90 public function test_comment_param_should_override_global() { 91 $comment = self::factory()->comment->create_and_get( array( 92 'comment_author_email' => $email = 'bar@example.org' 93 ) ); 94 95 $expected = sprintf( '<a href="mailto:%1$s">%2$s</a>', $email, $email ); 96 97 $this->assertEquals( $expected, get_comment_author_email_link( '', '', '', $comment ) ); 98 } 99 }