WordPress.org

Make WordPress Core

Changeset 1217 in tests


Ignore:
Timestamp:
02/16/13 02:07:42 (3 years ago)
Author:
nacin
Message:

Tests for post_parent__in and post_parent__not_in. props kovshenin. see #11056.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/query/results.php

    r1043 r1217  
    4444        $this->factory->post->create( array( 'post_title' => 'tags-a-and-c', 'tags_input' => array( 'tag-a', 'tag-c' ), 'post_date' => '2010-10-01 00:00:00' ) ); 
    4545 
     46        $this->parent_one = $this->factory->post->create( array( 'post_title' => 'parent-one', 'post_date' => '2007-01-01 00:00:00' ) ); 
     47        $this->parent_two = $this->factory->post->create( array( 'post_title' => 'parent-two', 'post_date' => '2007-01-01 00:00:00' ) ); 
     48        $this->parent_three = $this->factory->post->create( array( 'post_title' => 'parent-three', 'post_date' => '2007-01-01 00:00:00' ) ); 
     49        $this->factory->post->create( array( 'post_title' => 'child-one', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:01' ) ); 
     50        $this->factory->post->create( array( 'post_title' => 'child-two', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:02' ) ); 
     51        $this->factory->post->create( array( 'post_title' => 'child-three', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:03' ) ); 
     52        $this->factory->post->create( array( 'post_title' => 'child-four', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:04' ) ); 
     53 
    4654        unset( $this->q ); 
    4755        $this->q = new WP_Query(); 
     
    295303    } 
    296304 
     305    /** 
     306     * @ticket 11056 
     307     */ 
     308    function test_query_post_parent__in() { 
     309        // Query for first parent's children 
     310        $posts = $this->q->query( array( 
     311            'post_parent__in' => array( $this->parent_one ), 
     312            'orderby' => 'date', 
     313            'order' => 'asc', 
     314        ) ); 
     315 
     316        $this->assertEquals( array( 
     317            'child-one', 
     318            'child-two', 
     319        ), wp_list_pluck( $posts, 'post_title' ) ); 
     320 
     321        // Second parent's children 
     322        $posts = $this->q->query( array( 
     323            'post_parent__in' => array( $this->parent_two ), 
     324            'orderby' => 'date', 
     325            'order' => 'asc', 
     326        ) ); 
     327 
     328        $this->assertEquals( array( 
     329            'child-three', 
     330            'child-four', 
     331        ), wp_list_pluck( $posts, 'post_title' ) ); 
     332 
     333        // Both first and second parent's children 
     334        $posts = $this->q->query( array( 
     335            'post_parent__in' => array( $this->parent_one, $this->parent_two ), 
     336            'orderby' => 'date', 
     337            'order' => 'asc', 
     338        ) ); 
     339 
     340        $this->assertEquals( array( 
     341            'child-one', 
     342            'child-two', 
     343            'child-three', 
     344            'child-four', 
     345        ), wp_list_pluck( $posts, 'post_title' ) ); 
     346 
     347        // Third parent's children 
     348        $posts = $this->q->query( array( 
     349            'post_parent__in' => array( $this->parent_three ), 
     350        ) ); 
     351 
     352        $this->assertEquals( array(), wp_list_pluck( $posts, 'post_title' ) ); 
     353    } 
     354 
     355    /** 
     356     * @ticket 11056 
     357     */ 
     358    function test_query_orderby_post_parent__in() { 
     359        $posts = $this->q->query( array( 
     360            'post_parent__in' => array( $this->parent_two, $this->parent_one ), 
     361            'orderby' => 'post_parent__in', 
     362            'order' => 'asc', 
     363        ) ); 
     364 
     365        $this->assertEquals( array( 
     366            'child-three', 
     367            'child-four', 
     368            'child-one', 
     369            'child-two', 
     370        ), wp_list_pluck( $posts, 'post_title' ) ); 
     371    } 
    297372} 
Note: See TracChangeset for help on using the changeset viewer.