File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,9 +84,9 @@ function get_object_by_id( $post_id ) {
8484
8585class 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
9292class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing {
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments