From 04516c12991672487b6fa4ac5c444e8501a1a2a1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 2 Sep 2018 22:08:05 +0000 Subject: [PATCH] Taxonomy: Make sure `wp_list_categories()` correctly outputs term name of `0`. Props joyously, SergeyBiryukov. Fixes #44872. git-svn-id: https://develop.svn.wordpress.org/trunk@43605 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-walker-category.php | 2 +- .../tests/category/wpListCategories.php | 37 +++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/class-walker-category.php b/src/wp-includes/class-walker-category.php index e9975ef1af..4c155c721b 100644 --- a/src/wp-includes/class-walker-category.php +++ b/src/wp-includes/class-walker-category.php @@ -104,7 +104,7 @@ class Walker_Category extends Walker { ); // Don't generate an element if the category name is empty. - if ( ! $cat_name ) { + if ( '' === $cat_name ) { return; } diff --git a/tests/phpunit/tests/category/wpListCategories.php b/tests/phpunit/tests/category/wpListCategories.php index 6d428c8204..4d75b4ac00 100644 --- a/tests/phpunit/tests/category/wpListCategories.php +++ b/tests/phpunit/tests/category/wpListCategories.php @@ -103,6 +103,35 @@ class Tests_Category_WpListCategories extends WP_UnitTestCase { $this->assertNotContains( 'Test Cat 1', $found ); } + public function list_cats_callback( $cat ) { + if ( 'Test Cat 1' === $cat ) { + return ''; + } + + return $cat; + } + + /** + * @ticket 44872 + */ + public function test_should_create_element_when_cat_name_is_zero() { + $c = self::factory()->category->create( + array( + 'name' => '0', + ) + ); + + $found = wp_list_categories( + array( + 'hide_empty' => false, + 'echo' => false, + ) + ); + + $this->assertContains( "cat-item-$c", $found ); + $this->assertContains( '0', $found ); + } + public function test_show_option_all_link_should_go_to_home_page_when_show_on_front_is_false() { $cats = self::factory()->category->create_many( 2 ); @@ -247,14 +276,6 @@ class Tests_Category_WpListCategories extends WP_UnitTestCase { $this->assertContains( "
  • All
  • ", $found ); } - public function list_cats_callback( $cat ) { - if ( 'Test Cat 1' === $cat ) { - return ''; - } - - return $cat; - } - /** * @ticket 33460 */