Make WordPress Core


Ignore:
Timestamp:
12/18/2015 06:37:41 PM (9 years ago)
Author:
boonebgorges
Message:

Add current-cat-ancestor class to ancestor items in wp_list_categories().

Pairs nicely with current-cat-parent.

Props jrchamp, swisssipdy, ardathksheyna, wonderboymusic.
Fixes #10676.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/category/wpListCategories.php

    r36005 r36008  
    382382        $this->assertNotContains( '<li class="cat-item cat-item-' . $child4 . '">', $actual );
    383383    }
     384
     385    /**
     386     * @ticket 10676
     387     */
     388    public function test_class_containing_current_cat_ancestor() {
     389        $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
     390        $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
     391        $child2 = self::factory()->category->create( array( 'name' => 'Child 2', 'slug' => 'child2', 'parent' => $parent ) );
     392        $grandchild = self::factory()->category->create( array( 'name' => 'Grand Child', 'slug' => 'child', 'parent' => $child ) );
     393
     394        $actual = wp_list_categories( array(
     395            'echo'             => 0,
     396            'hide_empty'       => false,
     397            'current_category' => $grandchild,
     398        ) );
     399
     400        $this->assertRegExp( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     401        $this->assertRegExp( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     402        $this->assertNotRegExp( '/class="[^"]*cat-item-' . $grandchild . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     403        $this->assertNotRegExp( '/class="[^"]*cat-item-' . $child2 . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     404    }
    384405}
Note: See TracChangeset for help on using the changeset viewer.