WordPress.org

Make WordPress Core

Changeset 25976


Ignore:
Timestamp:
10/29/2013 01:49:05 AM (6 years ago)
Author:
nacin
Message:

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

Merges [25974] and [25975] to the 3.7 branch.

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

props chrisbliss18.
fixes #25750.

Location:
branches/3.7
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

  • branches/3.7/src

  • branches/3.7/src/wp-includes/post.php

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

    r25160 r25976  
    129129        $this->assertEqualSets( $child_ids, $post_ids );
    130130    }
     131
     132    /**
     133     * @ticket 25750
     134     */
     135    function test_get_pages_hierarchical_and_no_parent() {
     136        global $wpdb;
     137        $page_1 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     138        $page_2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) );
     139        $page_3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) );
     140        $page_4 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_2 ) );
     141
     142        $pages = get_pages(); // Defaults: hierarchical = true, parent = -1
     143        $pages_default_args = get_pages( array( 'hierarchical' => true, 'parent' => -1 ) );
     144        // Confirm the defaults.
     145        $this->assertEquals( $pages, $pages_default_args );
     146
     147        /*
     148         * Here's the tree we are testing:
     149         *
     150         * page 1
     151         * - page 2
     152         * -- page 4
     153         * - page 3
     154         *
     155         * If hierarchical => true works, the order will be 1,2,4,3.
     156         * If it doesn't, they will be in the creation order, 1,2,3,4.
     157         */
     158
     159        $this->assertEqualSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) );
     160    }
    131161}
Note: See TracChangeset for help on using the changeset viewer.