Comments: Add new tests missed in [44499].

Props dshanske, birgire.
Fixes #44033.


git-svn-id: https://develop.svn.wordpress.org/trunk@44502 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-01-09 06:19:53 +00:00
parent 36a2ed3f56
commit 62b4465532

View File

@ -0,0 +1,81 @@
<?php
/**
* Test cases for the `is_avatar_comment_type()` function.
*
* @package WordPress\UnitTests
*
* @since 5.1.0
*/
/**
* Tests_Comment_IsAvatarCommentType class.
*
* @group comment
* @covers is_avatar_comment_type
*
* @since 5.1.0
*/
class Tests_Comment_IsAvatarCommentType extends WP_UnitTestCase {
/**
* Test the `is_avatar_comment_type()` function.
*
* @since 5.1.0
*
* @dataProvider data_is_avatar_comment_type
*/
public function test_function( $comment_type, $expected ) {
$this->assertSame( $expected, is_avatar_comment_type( $comment_type ) );
}
/**
* Dataprovider for `is_avatar_comment_type()`.
*
* @since 5.1.0
*
* @return array {
* @type array {
* @type string Comment type.
* @type bool Expected values.
* }
* }
*/
public function data_is_avatar_comment_type() {
return array(
array( null, false ),
array( '', false ),
array( 'non-existing-comment-type', false ),
array( 'comment', true ),
);
}
/**
* The function should be filterable with the `get_avatar_comment_types` filter.
*
* @since 5.1.0
*/
public function test_function_should_be_filterable() {
$this->assertFalse( is_avatar_comment_type( 'review' ) );
add_filter( 'get_avatar_comment_types', array( $this, '_filter_avatar_comment_types' ) );
$actual_comment = is_avatar_comment_type( 'comment' );
$actual_review = is_avatar_comment_type( 'review' );
remove_filter( 'get_avatar_comment_types', array( $this, '_filter_avatar_comment_types' ) );
$this->assertTrue( $actual_comment );
$this->assertTrue( $actual_review );
}
/**
* Filters callback that modifies the list of allowed comment types for retrieving avatars.
*
* @since 5.1.0
*
* @param array $types An array of content types.
* @return array $types An array of content types.
*/
public function _filter_avatar_comment_types( $types ) {
$types[] = 'review';
return $types;
}
}