Skip to content

Commit

Permalink
Taxonomy: Make sure wp_list_categories() correctly outputs term nam…
Browse files Browse the repository at this point in the history
…e of `0`.

Props joyously, SergeyBiryukov.
Merges [43605] to the 5.0 branch.
Fixes #44872.

git-svn-id: https://develop.svn.wordpress.org/branches/5.0@43712 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Oct 11, 2018
1 parent 509cc81 commit 3b405ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/wp-includes/class-walker-category.php
Expand Up @@ -99,7 +99,7 @@ public function start_el( &$output, $category, $depth = 0, $args = array(), $id
);

// Don't generate an element if the category name is empty.
if ( ! $cat_name ) {
if ( '' === $cat_name ) {
return;
}

Expand Down
37 changes: 29 additions & 8 deletions tests/phpunit/tests/category/wpListCategories.php
Expand Up @@ -87,6 +87,35 @@ public function test_should_not_create_element_when_cat_name_is_filtered_to_empt
$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 );

Expand Down Expand Up @@ -207,14 +236,6 @@ public function test_show_option_all_link_should_link_to_post_archive_if_no_asso
$this->assertContains( "<li class='cat-item-all'><a href='" . $url . "'>All</a></li>", $found );
}

public function list_cats_callback( $cat ) {
if ( 'Test Cat 1' === $cat ) {
return '';
}

return $cat;
}

/**
* @ticket 33460
*/
Expand Down

0 comments on commit 3b405ba

Please sign in to comment.