Skip to content

Commit 93cfcca

Browse files
committed
Add unit test for tax_query against attachments.
See #22556. git-svn-id: https://develop.svn.wordpress.org/trunk@25278 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e8daea7 commit 93cfcca

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

tests/phpunit/includes/factory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ function get_object_by_id( $post_id ) {
8484

8585
class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post {
8686

87-
function create_object( $file, $parent = 0, $args = array() ) {
88-
return wp_insert_attachment( $args, $file, $parent );
89-
}
87+
function create_object( $file, $parent = 0, $args = array() ) {
88+
return wp_insert_attachment( $args, $file, $parent );
89+
}
9090
}
9191

9292
class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing {

tests/phpunit/tests/term/query.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,29 @@ function test_category__and_var() {
3737

3838
$this->assertEmpty( $posts2 );
3939
}
40+
41+
function test_taxonomy_with_attachments() {
42+
register_taxonomy_for_object_type( 'post_tag', 'attachment:image' );
43+
$tag_id = $this->factory->term->create( array( 'slug' => rand_str(), 'name' => rand_str() ) );
44+
$image_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
45+
'post_mime_type' => 'image/jpeg',
46+
'post_type' => 'attachment'
47+
) );
48+
wp_set_object_terms( $image_id, $tag_id, 'post_tag' );
49+
50+
$posts = $this->q->query( array(
51+
'fields' => 'ids',
52+
'post_type' => 'attachment',
53+
'post_status' => 'inherit',
54+
'tax_query' => array(
55+
array(
56+
'taxonomy' => 'post_tag',
57+
'field' => 'term_id',
58+
'terms' => array( $tag_id )
59+
)
60+
)
61+
) );
62+
63+
$this->assertEquals( array( $image_id ), $posts );
64+
}
4065
}

0 commit comments

Comments
 (0)