Make WordPress Core

Changeset 25974


Ignore:
Timestamp:
10/29/2013 01:46:01 AM (11 years ago)
Author:
nacin
Message:

Avoid resetting the 'hierarchical' argument in get_pages() when 'parent' is -1, the default.

Fixes a regression introduced in [25270]. Adds unit tests.

props chrisbliss18.
fixes #25750.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r25868 r25974  
    37073707        return $pages;
    37083708
    3709     if ( $parent && ! $child_of )
     3709    if ( $parent > 0 && ! $child_of )
    37103710        $hierarchical = false;
    37113711
  • trunk/tests/phpunit/tests/post.php

    r25972 r25974  
    830830        return $counts;
    831831    }
     832
     833    /**
     834     * @ticket 25750
     835     */
     836    function test_get_pages_hierarchical_and_no_parent() {
     837        global $wpdb;
     838        $page_1 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     839        $page_2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) );
     840        $page_3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) );
     841        $page_4 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_2 ) );
     842
     843        $pages = get_pages(); // Defaults: hierarchical = true, parent = -1
     844        $pages_default_args = get_pages( array( 'hierarchical' => true, 'parent' => -1 ) );
     845        // Confirm the defaults.
     846        $this->assertEquals( $pages, $pages_default_args );
     847
     848        /*
     849         * Here's the tree we are testing:
     850         *
     851         * page 1
     852         * - page 2
     853         * -- page 4
     854         * - page 3
     855         *
     856         * If hierarchical => true works, the order will be 1,2,4,3.
     857         * If it doesn't, they will be in the creation order, 1,2,3,4.
     858         */
     859
     860        $this->assertEqualSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) );
     861    }
    832862}
Note: See TracChangeset for help on using the changeset viewer.