WordPress.org

Make WordPress Core

Changeset 25278


Ignore:
Timestamp:
09/06/2013 02:43:49 PM (5 years ago)
Author:
wonderboymusic
Message:

Add unit test for tax_query against attachments.

See #22556.

Location:
trunk/tests/phpunit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/factory.php

    r25002 r25278  
    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
  • trunk/tests/phpunit/tests/term/query.php

    r25238 r25278  
    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}
Note: See TracChangeset for help on using the changeset viewer.