Make WordPress Core


Ignore:
Timestamp:
08/20/2016 05:34:13 PM (8 years ago)
Author:
boonebgorges
Message:

Allow attachment taxonomies to be fetched as objects.

By adding the $output parameter to get_attachment_taxonomies(), the
function signature matches that of get_object_taxonomies(). The change
also allows for more consistent behavior when passing output=objects
to get_object_taxonomies() for the 'attachment' object type, since
the $output parameter is now passed through the function stack.

Props codemovement.pk.
See #37368.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/taxonomy/getObjectTaxonomies.php

    r38290 r38292  
    4646        $this->assertSame( $expected, $found );
    4747    }
     48
     49    /**
     50     * @ticket 37368
     51     */
     52    public function test_should_return_all_attachment_taxonomies_for_attachment_object_type() {
     53        register_taxonomy( 'wptests_tax2', 'attachment:image' );
     54
     55        $a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
     56            'post_mime_type' => 'image/jpeg',
     57            'post_type' => 'attachment'
     58        ) );
     59        $attachment = get_post( $a );
     60
     61        $found = get_object_taxonomies( $attachment, 'names' );
     62
     63        $this->assertSame( array( 'wptests_tax2' ), $found );
     64    }
     65
     66    /**
     67     * @ticket 37368
     68     */
     69    public function test_should_respect_output_objects_when_object_is_attachment() {
     70        register_taxonomy( 'wptests_tax2', 'attachment:image' );
     71
     72        $a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
     73            'post_mime_type' => 'image/jpeg',
     74            'post_type' => 'attachment'
     75        ) );
     76        $attachment = get_post( $a );
     77
     78        $found = get_object_taxonomies( $attachment, 'objects' );
     79
     80        $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
     81        $this->assertInternalType( 'object', $found['wptests_tax2'] );
     82        $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name );
     83    }
    4884}
Note: See TracChangeset for help on using the changeset viewer.