diff --git a/tests/phpunit/includes/factory.php b/tests/phpunit/includes/factory.php index bf5ba53777..39131492b1 100644 --- a/tests/phpunit/includes/factory.php +++ b/tests/phpunit/includes/factory.php @@ -84,9 +84,9 @@ class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing { class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { - function create_object( $file, $parent = 0, $args = array() ) { - return wp_insert_attachment( $args, $file, $parent ); - } + function create_object( $file, $parent = 0, $args = array() ) { + return wp_insert_attachment( $args, $file, $parent ); + } } class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing { diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 15c85a0dd4..44eb5f9243 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -37,4 +37,29 @@ class Tests_Tax_Query extends WP_UnitTestCase { $this->assertEmpty( $posts2 ); } + + function test_taxonomy_with_attachments() { + register_taxonomy_for_object_type( 'post_tag', 'attachment:image' ); + $tag_id = $this->factory->term->create( array( 'slug' => rand_str(), 'name' => rand_str() ) ); + $image_id = $this->factory->attachment->create_object( 'image.jpg', 0, array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment' + ) ); + wp_set_object_terms( $image_id, $tag_id, 'post_tag' ); + + $posts = $this->q->query( array( + 'fields' => 'ids', + 'post_type' => 'attachment', + 'post_status' => 'inherit', + 'tax_query' => array( + array( + 'taxonomy' => 'post_tag', + 'field' => 'term_id', + 'terms' => array( $tag_id ) + ) + ) + ) ); + + $this->assertEquals( array( $image_id ), $posts ); + } } \ No newline at end of file