| 373 | |
| 374 | /** |
| 375 | * Tests various search scenarios |
| 376 | * @group query |
| 377 | */ |
| 378 | class Tests_Query_Search extends WP_UnitTestCase { |
| 379 | |
| 380 | /** |
| 381 | * @ticket 7394 |
| 382 | */ |
| 383 | function test_query_search_orderby_relevance() { |
| 384 | $this->factory->post->create( array( 'post_title' => 'foo test post bar', 'post_date' => '2009-12-01 00:00:01' ) ); |
| 385 | $this->factory->post->create( array( 'post_title' => 'foo bar test post', 'post_date' => '2009-12-01 00:00:02' ) ); |
| 386 | $this->factory->post->create( array( 'post_title' => 'foo test bar post baz', 'post_date' => '2009-12-01 00:00:03' ) ); |
| 387 | $this->factory->post->create( array( 'post_title' => 'foo test bar', 'post_date' => '2009-12-01 00:00:04' ) ); |
| 388 | $this->factory->post->create( array( 'post_title' => 'foo post bar', 'post_date' => '2009-12-01 00:00:05' ) ); |
| 389 | $this->factory->post->create( array( 'post_title' => 'foo', 'post_content' => 'foo test post bar', 'post_date' => '2009-12-01 00:00:06' ) ); |
| 390 | $this->factory->post->create( array( 'post_title' => 'foo', 'post_content' => 'foo test bar', 'post_date' => '2009-12-01 00:00:07' ) ); |
| 391 | |
| 392 | $posts = new WP_Query( array( |
| 393 | 's' => 'test post', |
| 394 | ) ); |
| 395 | |
| 396 | $this->assertEquals( array( |
| 397 | 'foo bar test post', |
| 398 | 'foo test post bar', |
| 399 | 'foo test bar post baz', |
| 400 | 'foo test bar', |
| 401 | 'foo', |
| 402 | ), wp_list_pluck( $posts->posts, 'post_title' ) ); |
| 403 | |
| 404 | $posts = new WP_Query( array( |
| 405 | 's' => 'post bar', |
| 406 | ) ); |
| 407 | |
| 408 | $this->assertEquals( array( |
| 409 | 'foo post bar', |
| 410 | 'foo test post bar', |
| 411 | 'foo test bar post baz', |
| 412 | 'foo bar test post', |
| 413 | 'foo test bar', |
| 414 | 'foo', |
| 415 | ), wp_list_pluck( $posts->posts, 'post_title' ) ); |
| 416 | |
| 417 | $posts = new WP_Query( array( |
| 418 | 's' => 'post', |
| 419 | ) ); |
| 420 | |
| 421 | $this->assertEquals( array( |
| 422 | 'foo post bar', |
| 423 | 'foo test bar post baz', |
| 424 | 'foo bar test post', |
| 425 | 'foo test post bar', |
| 426 | 'foo', |
| 427 | 'foo test bar', |
| 428 | ), wp_list_pluck( $posts->posts, 'post_title' ) ); |
| 429 | |
| 430 | // Let's just make sure order by date is not broken |
| 431 | $posts = new WP_Query( array( |
| 432 | 's' => 'test post', |
| 433 | 'orderby' => 'date', |
| 434 | ) ); |
| 435 | |
| 436 | $this->assertEquals( array( |
| 437 | 'foo', |
| 438 | 'foo test bar', |
| 439 | 'foo test bar post baz', |
| 440 | 'foo bar test post', |
| 441 | 'foo test post bar', |
| 442 | ), wp_list_pluck( $posts->posts, 'post_title' ) ); |
| 443 | } |
| 444 | } |
| 445 | No newline at end of file |