diff --git a/tests/phpunit/tests/post/query.php b/tests/phpunit/tests/post/query.php index 2e31f4d24e..1d746fc0b7 100644 --- a/tests/phpunit/tests/post/query.php +++ b/tests/phpunit/tests/post/query.php @@ -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' ) ); + } } \ No newline at end of file