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
This commit is contained in:
Scott Taylor 2013-09-06 14:43:49 +00:00
parent e8daea7de7
commit 93cfccac2d
2 changed files with 28 additions and 3 deletions

View File

@ -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 {

View File

@ -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 );
}
}