Make WordPress Core

Changeset 28619


Ignore:
Timestamp:
05/29/2014 06:23:58 PM (11 years ago)
Author:
wonderboymusic
Message:

Add unit tests to confirm that post__in orderby is working as expected with menu_order based on comments from #28012.

File:
1 edited

Legend:

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

    r26490 r28619  
    678678        return $posts;
    679679    }
     680
     681    function test_post__in_ordering() {
     682        $post_id1 = $this->factory->post->create( array( 'post_type' => 'page', 'menu_order' => rand( 1, 100 ) ) );
     683        $post_id2 = $this->factory->post->create( array( 'post_type' => 'page', 'menu_order' => rand( 1, 100 ) ) );
     684        $post_id3 = $this->factory->post->create( array(
     685            'post_type' => 'page',
     686            'post_parent' => $post_id2,
     687            'menu_order' => rand( 1, 100 )
     688        ) );
     689        $post_id4 = $this->factory->post->create( array(
     690            'post_type' => 'page',
     691            'post_parent' => $post_id2,
     692            'menu_order' => rand( 1, 100 )
     693        ) );
     694        $post_id5 = $this->factory->post->create( array( 'post_type' => 'page', 'menu_order' => rand( 1, 100 ) ) );
     695
     696        $ordered = array( $post_id2, $post_id4, $post_id3, $post_id1, $post_id5 );
     697
     698        $q = new WP_Query( array(
     699            'post_type' => 'any',
     700            'post__in' => $ordered,
     701            'orderby' => 'post__in'
     702        ) );
     703        $this->assertEqualSets( $ordered, wp_list_pluck( $q->posts, 'ID' ) );
     704    }
     705
     706    function test_post__in_attachment_ordering() {
     707        $post_id = $this->factory->post->create();
     708        $att_ids = array();
     709        $att_ids[1] = $this->factory->attachment->create_object( 'woo1.jpg', $post_id, array(
     710            'post_mime_type' => 'image/jpeg',
     711            'menu_order' => rand( 1, 100 )
     712        ) );
     713        $att_ids[2] = $this->factory->attachment->create_object( 'woo2.jpg', $post_id, array(
     714            'post_mime_type' => 'image/jpeg',
     715            'menu_order' => rand( 1, 100 )
     716        ) );
     717        $att_ids[3] = $this->factory->attachment->create_object( 'woo3.jpg', $post_id, array(
     718            'post_mime_type' => 'image/jpeg',
     719            'menu_order' => rand( 1, 100 )
     720        ) );
     721        $att_ids[4] = $this->factory->attachment->create_object( 'woo4.jpg', $post_id, array(
     722            'post_mime_type' => 'image/jpeg',
     723            'menu_order' => rand( 1, 100 )
     724        ) );
     725        $att_ids[5] = $this->factory->attachment->create_object( 'woo5.jpg', $post_id, array(
     726            'post_mime_type' => 'image/jpeg',
     727            'menu_order' => rand( 1, 100 )
     728        ) );
     729
     730        $ordered = array( $att_ids[5], $att_ids[1], $att_ids[4], $att_ids[3], $att_ids[2] );
     731
     732        $attached = new WP_Query( array(
     733            'post__in' => $ordered,
     734            'post_type' => 'attachment',
     735            'post_parent' => $post_id,
     736            'post_mime_type' => 'image',
     737            'post_status' => 'inherit',
     738            'posts_per_page' => '-1',
     739            'orderby' => 'post__in'
     740        ) );
     741        $this->assertEqualSets( $ordered, wp_list_pluck( $attached->posts, 'ID' ) );
     742    }
    680743}
Note: See TracChangeset for help on using the changeset viewer.