| | 387 | /** |
| | 388 | * @ticket 22744 |
| | 389 | */ |
| | 390 | public function test_include_file_names_in_attachment_search_with_meta_query() { |
| | 391 | $attachment = self::factory()->post->create( array( |
| | 392 | 'post_type' => 'attachment', |
| | 393 | 'post_status' => 'publish', |
| | 394 | 'post_title' => 'bar foo', |
| | 395 | 'post_content' => 'foo bar', |
| | 396 | 'post_excerpt' => 'This post has foo', |
| | 397 | ) ); |
| | 398 | |
| | 399 | add_post_meta( $attachment, '_wp_attached_file', 'some-image4.png', true ); |
| | 400 | add_post_meta( $attachment, '_test_meta_key', 'value', true ); |
| | 401 | add_filter( 'posts_clauses', '_filter_query_attachment_filenames' ); |
| | 402 | |
| | 403 | // Pass post_type a string value. |
| | 404 | $q = new WP_Query( array( |
| | 405 | 's' => 'image4', |
| | 406 | 'fields' => 'ids', |
| | 407 | 'post_type' => 'attachment', |
| | 408 | 'post_status' => 'inherit', |
| | 409 | 'meta_query' => array( |
| | 410 | array( |
| | 411 | 'key' => '_test_meta_key', |
| | 412 | 'value' => 'value', |
| | 413 | 'compare' => '=', |
| | 414 | ), |
| | 415 | ), |
| | 416 | ) ); |
| | 417 | |
| | 418 | $this->assertSame( array( $attachment ), $q->posts ); |
| | 419 | } |
| | 420 | |
| | 421 | /** |
| | 422 | * @ticket 22744 |
| | 423 | */ |
| | 424 | public function test_include_file_names_in_attachment_search_with_tax_query() { |
| | 425 | $attachment = self::factory()->post->create( array( |
| | 426 | 'post_type' => 'attachment', |
| | 427 | 'post_status' => 'publish', |
| | 428 | 'post_title' => 'bar foo', |
| | 429 | 'post_content' => 'foo bar', |
| | 430 | 'post_excerpt' => 'This post has foo', |
| | 431 | ) ); |
| | 432 | |
| | 433 | // Add a tag to the post. |
| | 434 | wp_set_post_terms( $attachment, 'test', 'post_tag' ); |
| | 435 | |
| | 436 | add_post_meta( $attachment, '_wp_attached_file', 'some-image5.png', true ); |
| | 437 | add_filter( 'posts_clauses', '_filter_query_attachment_filenames' ); |
| | 438 | |
| | 439 | // Pass post_type a string value. |
| | 440 | $q = new WP_Query( array( |
| | 441 | 's' => 'image5', |
| | 442 | 'fields' => 'ids', |
| | 443 | 'post_type' => 'attachment', |
| | 444 | 'post_status' => 'inherit', |
| | 445 | 'tax_query' => array( |
| | 446 | array( |
| | 447 | 'taxonomy' => 'post_tag', |
| | 448 | 'field' => 'slug', |
| | 449 | 'terms' => 'test', |
| | 450 | ), |
| | 451 | ), |
| | 452 | ) ); |
| | 453 | |
| | 454 | $this->assertSame( array( $attachment ), $q->posts ); |
| | 455 | } |
| | 456 | |
| | 457 | /** |
| | 458 | * @ticket 22744 |
| | 459 | */ |
| | 460 | public function test_filter_query_attachment_filenames_unhooks_itself() { |
| | 461 | add_filter( 'posts_clauses', '_filter_query_attachment_filenames' ); |
| | 462 | |
| | 463 | apply_filters( 'posts_clauses', array( |
| | 464 | 'where' => '', |
| | 465 | 'groupby' => '', |
| | 466 | 'join' => '', |
| | 467 | 'orderby' => '', |
| | 468 | 'distinct' => '', |
| | 469 | 'fields' => '', |
| | 470 | 'limit' => '', |
| | 471 | ) ); |
| | 472 | |
| | 473 | $result = has_filter( 'posts_clauses', '_filter_query_attachment_filenames' ); |
| | 474 | |
| | 475 | $this->assertFalse( $result ); |
| | 476 | } |
| | 477 | |