Add unit tests to confirm that post__in
orderby is working as expected with menu_order
based on comments from #28012.
git-svn-id: https://develop.svn.wordpress.org/trunk@28619 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
25593e291c
commit
fcff169970
@ -677,4 +677,67 @@ class Tests_Post_Query extends WP_UnitTestCase {
|
||||
|
||||
return $posts;
|
||||
}
|
||||
|
||||
function test_post__in_ordering() {
|
||||
$post_id1 = $this->factory->post->create( array( 'post_type' => 'page', 'menu_order' => rand( 1, 100 ) ) );
|
||||
$post_id2 = $this->factory->post->create( array( 'post_type' => 'page', 'menu_order' => rand( 1, 100 ) ) );
|
||||
$post_id3 = $this->factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
'post_parent' => $post_id2,
|
||||
'menu_order' => rand( 1, 100 )
|
||||
) );
|
||||
$post_id4 = $this->factory->post->create( array(
|
||||
'post_type' => 'page',
|
||||
'post_parent' => $post_id2,
|
||||
'menu_order' => rand( 1, 100 )
|
||||
) );
|
||||
$post_id5 = $this->factory->post->create( array( 'post_type' => 'page', 'menu_order' => rand( 1, 100 ) ) );
|
||||
|
||||
$ordered = array( $post_id2, $post_id4, $post_id3, $post_id1, $post_id5 );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'post_type' => 'any',
|
||||
'post__in' => $ordered,
|
||||
'orderby' => 'post__in'
|
||||
) );
|
||||
$this->assertEqualSets( $ordered, wp_list_pluck( $q->posts, 'ID' ) );
|
||||
}
|
||||
|
||||
function test_post__in_attachment_ordering() {
|
||||
$post_id = $this->factory->post->create();
|
||||
$att_ids = array();
|
||||
$att_ids[1] = $this->factory->attachment->create_object( 'woo1.jpg', $post_id, array(
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'menu_order' => rand( 1, 100 )
|
||||
) );
|
||||
$att_ids[2] = $this->factory->attachment->create_object( 'woo2.jpg', $post_id, array(
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'menu_order' => rand( 1, 100 )
|
||||
) );
|
||||
$att_ids[3] = $this->factory->attachment->create_object( 'woo3.jpg', $post_id, array(
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'menu_order' => rand( 1, 100 )
|
||||
) );
|
||||
$att_ids[4] = $this->factory->attachment->create_object( 'woo4.jpg', $post_id, array(
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'menu_order' => rand( 1, 100 )
|
||||
) );
|
||||
$att_ids[5] = $this->factory->attachment->create_object( 'woo5.jpg', $post_id, array(
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'menu_order' => rand( 1, 100 )
|
||||
) );
|
||||
|
||||
$ordered = array( $att_ids[5], $att_ids[1], $att_ids[4], $att_ids[3], $att_ids[2] );
|
||||
|
||||
$attached = new WP_Query( array(
|
||||
'post__in' => $ordered,
|
||||
'post_type' => 'attachment',
|
||||
'post_parent' => $post_id,
|
||||
'post_mime_type' => 'image',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => '-1',
|
||||
'orderby' => 'post__in'
|
||||
) );
|
||||
$this->assertEqualSets( $ordered, wp_list_pluck( $attached->posts, 'ID' ) );
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user