Make WordPress Core

Changeset 34698


Ignore:
Timestamp:
09/29/2015 08:49:32 PM (9 years ago)
Author:
DrewAPicture
Message:

Tests: Add two tests for the current 'hierarchical' argument behavior in get_pages().

See #18701.

File:
1 edited

Legend:

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

    r30735 r34698  
    215215    }
    216216
     217    /**
     218     * @ticket 18701
     219     */
     220    public function test_get_pages_hierarchical_empty_child_of() {
     221        $page_1 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     222        $page_2 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     223        $page_3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) );
     224        $page_4 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) );
     225
     226        $pages = get_pages(); // Defaults: hierarchical = true, child_of = '', parent = -1
     227        $default_args = get_pages( array(
     228            'hierarchical' => true,
     229            'child_of'     => ''
     230        ) );
     231
     232        $this->assertEquals( $pages, $default_args );
     233
     234        /*
     235         * Page tree:
     236         *
     237         * page 1 (parent 0)
     238         * – page 3 (parent 1)
     239         * – page 4 (parent 1)
     240         * page 2 (parent 0)
     241         *
     242         * With default arguments, if child_of is empty (normalized to 0), only pages with a matching
     243         * post_parent will be returned, in the order they were created: 1, 2.
     244         */
     245
     246        $found_pages = wp_list_filter( $pages, array( 'post_parent' => 0 ) );
     247
     248        $this->assertEqualSets( array( $page_1, $page_2 ), wp_list_pluck( $found_pages, 'ID' ) );
     249    }
     250
     251    /**
     252     * @ticket 18701
     253     */
     254    public function test_get_pages_non_hierarchical_empty_child_of() {
     255        $page_1 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     256        $page_2 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     257        $page_3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) );
     258        $page_4 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) );
     259
     260        $pages = get_pages( array( 'hierarchical' => false ) ); // child_of = '', parent = -1
     261
     262        /*
     263         * Page tree:
     264         *
     265         * page 1 (parent 0)
     266         * – page 3 (parent 1)
     267         * – page 4 (parent 1)
     268         * page 2 (parent 0)
     269         *
     270         * If hierarchical is false and child_of is empty (normalized to 0), pages will be returned
     271         * in order of creation: 1, 2, 3, 4, regardless of parent.
     272         */
     273
     274        $this->assertEqualSets( array( $page_1, $page_2, $page_3, $page_4 ), wp_list_pluck( $pages, 'ID' ) );
     275    }
     276
    217277    function test_wp_list_pages_classes() {
    218278        $type = 'taco';
Note: See TracChangeset for help on using the changeset viewer.