3.7 regression from [25119]: Have in_category() return false when the first argument is empty.
Adds unit tests. props ericlewis. fixes #25706 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@25923 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
99a4f77ea7
commit
559dc21202
@ -232,6 +232,9 @@ function get_the_category_list( $separator = '', $parents='', $post_id = false )
|
||||
* @return bool True if the current post is in any of the given categories.
|
||||
*/
|
||||
function in_category( $category, $post = null ) {
|
||||
if ( empty( $category ) )
|
||||
return false;
|
||||
|
||||
return has_category( $category, $post );
|
||||
}
|
||||
|
||||
|
@ -152,4 +152,20 @@ class Tests_Taxonomy extends WP_UnitTestCase {
|
||||
_unregister_post_type( $post_type );
|
||||
|
||||
}
|
||||
/**
|
||||
* @ticket 25706
|
||||
*/
|
||||
function test_in_category() {
|
||||
$post = $this->factory->post->create_and_get();
|
||||
|
||||
// in_category() returns false when first parameter is empty()
|
||||
$this->assertFalse( in_category( '', $post ) );
|
||||
$this->assertFalse( in_category( false, $post ) );
|
||||
$this->assertFalse( in_category( null, $post ) );
|
||||
|
||||
// Test expected behavior of in_category()
|
||||
$term = wp_insert_term( 'Test', 'category' );
|
||||
wp_set_object_terms( $post->ID, $term['term_id'], 'category' );
|
||||
$this->assertTrue( in_category( $term['term_id'], $post ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user