Make WordPress Core

Ticket #10676: 10676.2.diff

File 10676.2.diff, 2.2 KB (added by swissspidy, 8 years ago)
  • src/wp-includes/class-walker-category.php

    diff --git src/wp-includes/class-walker-category.php src/wp-includes/class-walker-category.php
    index da518c9..8ef3c58 100644
    class Walker_Category extends Walker { 
    170170                                        } elseif ( $category->term_id == $_current_term->parent ) {
    171171                                                $css_classes[] = 'current-cat-parent';
    172172                                        }
     173                                        while ( $_current_term->parent ) {
     174                                                if ( $category->term_id == $_current_term->parent ) {
     175                                                        $css_classes[] =  'current-cat-ancestor';
     176                                                        break;
     177                                                }
     178                                                $_current_term = get_term( $_current_term->parent, $category->taxonomy );
     179                                        }
    173180                                }
    174181                        }
    175182
  • tests/phpunit/tests/category/wpListCategories.php

    diff --git tests/phpunit/tests/category/wpListCategories.php tests/phpunit/tests/category/wpListCategories.php
    index 048f72d..e1b6884 100644
    class Tests_Category_WpListCategories extends WP_UnitTestCase { 
    307307
    308308                $this->assertNotContains( '<li class="cat-item cat-item-' . $child2 . '">', $actual );
    309309        }
     310
     311        /**
     312         * @ticket 10676
     313         */
     314        public function test_class_containing_current_cat_ancestor() {
     315                $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
     316                $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
     317                $child2 = self::factory()->category->create( array( 'name' => 'Child 2', 'slug' => 'child2', 'parent' => $parent ) );
     318                $grandchild = self::factory()->category->create( array( 'name' => 'Grand Child', 'slug' => 'child', 'parent' => $child ) );
     319
     320                $actual = wp_list_categories( array(
     321                        'echo'             => 0,
     322                        'hide_empty'       => false,
     323                        'current_category' => $grandchild,
     324                ) );
     325
     326                $this->assertRegExp( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     327                $this->assertRegExp( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     328                $this->assertNotRegExp( '/class="[^"]*cat-item-' . $grandchild . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     329                $this->assertNotRegExp( '/class="[^"]*cat-item-' . $child2 . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     330        }
    310331}