| 11 | static $post_ids = array(); |
| 12 | |
| 13 | public static function wpSetUpBeforeClass( $factory ) { |
| 14 | |
| 15 | self::$post_ids[] = $factory->post->create( array( 'post_status' => 'publish', |
| 16 | 'post_title' => 'Test post 1', |
| 17 | 'post_content' => '', |
| 18 | 'post_excerpt' => '' |
| 19 | ) ); |
| 20 | self::$post_ids[] = $factory->post->create( array( 'post_status' => 'publish', |
| 21 | 'post_title' => '', |
| 22 | 'post_content' => 'Test post 2', |
| 23 | 'post_excerpt' => '' |
| 24 | ) ); |
| 25 | self::$post_ids[] = $factory->post->create( array( 'post_status' => 'publish', |
| 26 | 'post_title' => '', |
| 27 | 'post_content' => '', |
| 28 | 'post_excerpt' => 'Test post 3' |
| 29 | ) ); |
| 30 | } |
| 31 | |
| 32 | public static function wpTearDownAfterClass() { |
| 33 | foreach( self::$post_ids as $id ) { |
| 34 | wp_delete_post( $id ); |
| 35 | } |
| 36 | } |
| 37 | |
| 360 | * @ticket 39055 |
| 361 | */ |
| 362 | public function test_search_order_with_include_array_when_no_order_specified() { |
| 363 | $include_array = array ( self::$post_ids[1], self::$post_ids[0], self::$post_ids[2] ); |
| 364 | |
| 365 | $q = new WP_Query( array( |
| 366 | 'include' => $include_array, |
| 367 | 'orderby' => 'include', |
| 368 | 'fields' => 'ids' |
| 369 | ) ); |
| 370 | |
| 371 | // Expect same order as 'include' array when no 'order' param is passed in |
| 372 | $this->assertSame( $include_array, $q->posts ); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * @ticket 39055 |
| 377 | */ |
| 378 | public function test_search_order_with_include_array_when_order_asc() { |
| 379 | $include_array = array ( self::$post_ids[1], self::$post_ids[0], self::$post_ids[2] ); |
| 380 | |
| 381 | $q = new WP_Query( array( |
| 382 | 'include' => $include_array, |
| 383 | 'orderby' => 'include', |
| 384 | 'order' => 'asc', |
| 385 | 'fields' => 'ids' |
| 386 | ) ); |
| 387 | |
| 388 | // Expect same order as 'include' array when order=asc is passed in |
| 389 | $this->assertSame( $include_array, $q->posts ); |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * @ticket 39055 |
| 394 | */ |
| 395 | public function test_search_order_with_include_array_when_order_desc() { |
| 396 | $include_array = array ( self::$post_ids[1], self::$post_ids[0], self::$post_ids[2] ); |
| 397 | $expected_returned_array = array_reverse( $include_array ); |
| 398 | |
| 399 | $q = new WP_Query( array( |
| 400 | 'include' => $include_array, |
| 401 | 'orderby' => 'include', |
| 402 | 'order' => 'desc', |
| 403 | 'fields' => 'ids' |
| 404 | ) ); |
| 405 | |
| 406 | // Expect reverse order of 'include' array when order=desc is passed in |
| 407 | $this->assertSame( $expected_returned_array, $q->posts ); |
| 408 | } |
| 409 | |
| 410 | /** |