Make WordPress Core


Ignore:
Timestamp:
09/04/2013 08:55:05 PM (11 years ago)
Author:
wonderboymusic
Message:

Allow get_pages() to accept an array for the arg parent. Adds unit tests, some will fail until the next commit.

Fixes #9470.

File:
1 edited

Legend:

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

    r25168 r25244  
    824824        $this->assertEquals( $inc, $exc_result );
    825825    }
     826
     827    function test_get_pages_parent() {
     828        $page_id1 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     829        $page_id2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id1 ) );
     830        $page_id3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id2 ) );
     831        $page_id4 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id1 ) );
     832
     833        $pages = get_pages( array( 'parent' => 0, 'hierarchical' => false ) );
     834        $this->assertEqualSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) );
     835
     836        $pages = get_pages( array( 'parent' => $page_id1, 'hierarchical' => false ) );
     837        $this->assertEqualSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
     838
     839        $pages = get_pages( array( 'parent' => array( $page_id1, $page_id2 ), 'hierarchical' => false ) );
     840        $this->assertEqualSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
     841
     842        $pages = get_pages( array( 'parent' => 0 ) );
     843        $this->assertEqualSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) );
     844
     845        $pages = get_pages( array( 'parent' => $page_id1 ) );
     846        $this->assertEqualSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
     847
     848        $pages = get_pages( array( 'parent' => array( $page_id1, $page_id2 ) ) );
     849        $this->assertEqualSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
     850    }
    826851}
Note: See TracChangeset for help on using the changeset viewer.