Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/wp-admin/includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,18 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
<li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>>

<?php
$comment_row_class = '';
$avatar = '';

if ( get_option( 'show_avatars' ) ) {
echo get_avatar( $comment, 50, 'mystery' );
$comment_row_class .= ' has-avatar';
$avatar = get_avatar( $comment, 50, 'mystery' );
echo $avatar;
}
?>

<div class="dashboard-comment-wrap has-row-actions<?php echo $avatar ? ' has-avatar' : ''; ?>">

<?php if ( ! $comment->comment_type || 'comment' === $comment->comment_type ) : ?>

<div class="dashboard-comment-wrap has-row-actions <?php echo $comment_row_class; ?>">
<p class="comment-meta">
<?php
// Comments might not have a post they relate to, e.g. programmatically created ones.
Expand Down Expand Up @@ -902,7 +903,6 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
}
$type = esc_html( $type );
?>
<div class="dashboard-comment-wrap has-row-actions">
<p class="comment-meta">
<?php
// Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
Expand Down
95 changes: 95 additions & 0 deletions tests/phpunit/tests/admin/wpDashboardRecentCommentsRow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/**
* @group admin
* @group dashboard
*
* @covers ::_wp_dashboard_recent_comments_row
*/
class Tests_Admin_wpDashboardRecentCommentsRow extends WP_UnitTestCase {

public function set_up() {
parent::set_up();

require_once ABSPATH . 'wp-admin/includes/dashboard.php';

update_option( 'show_avatars', 1 );
add_filter( 'get_avatar_comment_types', array( $this, 'filter_avatar_comment_types' ) );
}

public function filter_avatar_comment_types( $types ) {
$types[] = 'example_review';
return $types;
}

/**
* @ticket 66889
*
* @dataProvider data_comment_types
*
* @param string $comment_type Comment type.
*/
public function test_row_wrapper_has_avatar_class_when_avatar_is_rendered( $comment_type ) {
$comment = self::factory()->comment->create_and_get(
array(
'comment_post_ID' => self::factory()->post->create(),
'comment_type' => $comment_type,
)
);

$output = get_echo( '_wp_dashboard_recent_comments_row', array( &$comment ) );

$this->assertStringContainsString( '<img', $output, 'An avatar should be rendered.' );
$this->assertMatchesRegularExpression( '/class="dashboard-comment-wrap[^"]*\shas-avatar"/', $output );
}

/**
* @ticket 66889
*
* @dataProvider data_comment_types
*
* @param string $comment_type Comment type.
*/
public function test_row_wrapper_has_no_avatar_class_when_avatars_are_disabled( $comment_type ) {
update_option( 'show_avatars', 0 );

$comment = self::factory()->comment->create_and_get(
array(
'comment_post_ID' => self::factory()->post->create(),
'comment_type' => $comment_type,
)
);

$output = get_echo( '_wp_dashboard_recent_comments_row', array( &$comment ) );

$this->assertStringNotContainsString( 'has-avatar', $output );
}

/**
* @ticket 66889
*/
public function test_row_wrapper_has_no_avatar_class_when_avatar_is_not_rendered() {
$comment = self::factory()->comment->create_and_get(
array(
'comment_post_ID' => self::factory()->post->create(),
'comment_type' => 'pingback',
)
);

$output = get_echo( '_wp_dashboard_recent_comments_row', array( &$comment ) );

$this->assertStringNotContainsString( 'has-avatar', $output, 'Pingbacks do not get avatars by default.' );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_comment_types() {
return array(
'regular comment' => array( 'comment' ),
'custom type' => array( 'example_review' ),
);
}
}
Loading