Make WordPress Core


Ignore:
Timestamp:
03/26/2014 10:46:16 PM (10 years ago)
Author:
wonderboymusic
Message:

In wp_list_pages(), add the current_page_item class where applicable when used with a custom post type.

Adds a unit test.

Props nacin.
Fixes #17590.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/getPages.php

    r25975 r27755  
    212212        $this->assertEqualSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) );
    213213    }
     214
     215    function test_wp_list_pages_classes() {
     216        $type = 'taco';
     217        register_post_type( $type, array( 'hierarchical' => true, 'public' => true ) );
     218
     219        $posts = $this->factory->post->create_many( 2, array( 'post_type' => $type ) );
     220        $post_id = reset( $posts );
     221
     222        $this->go_to( "/?p=$post_id&post_type=$type" );
     223
     224        $this->assertEquals( $post_id, get_queried_object_id() );
     225
     226        $output = wp_list_pages( array(
     227            'echo' => false,
     228            'title_li' => '',
     229            'post_type' => $type
     230        ) );
     231
     232        $this->assertNotEmpty( $output );
     233        $this->assertEquals( 2, substr_count( $output, 'class="page_item ' ) );
     234        $this->assertContains( 'current_page_item', $output );
     235        $this->assertEquals( 1, substr_count( $output, 'current_page_item' ) );
     236
     237        _unregister_post_type( $type );
     238    }
    214239}
Note: See TracChangeset for help on using the changeset viewer.