diff --git a/tests/phpunit/tests/media/getAttachmentTaxonomies.php b/tests/phpunit/tests/media/getAttachmentTaxonomies.php new file mode 100644 index 0000000000..c3c7bf49a7 --- /dev/null +++ b/tests/phpunit/tests/media/getAttachmentTaxonomies.php @@ -0,0 +1,82 @@ +attachment->create_object( 'image.jpg', 0, array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment' + ) ); + $attachment = get_post( $a ); + + $found = get_attachment_taxonomies( $attachment, 'names' ); + $expected = array( 'wptests_tax' ); + + $this->assertSame( $expected, $found ); + } + + public function test_should_return_taxonomy_registered_for_specific_attachment_type() { + register_taxonomy( 'wptests_tax', 'attachment:image' ); + + $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment' + ) ); + $attachment = get_post( $a ); + + $found = get_attachment_taxonomies( $attachment, 'names' ); + $expected = array( 'wptests_tax' ); + + $this->assertSame( $expected, $found ); + } + + public function test_should_return_taxonomy_registered_for_specific_attachment_mimetype() { + register_taxonomy( 'wptests_tax', 'attachment:image/jpeg' ); + + $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment' + ) ); + $attachment = get_post( $a ); + + $found = get_attachment_taxonomies( $attachment, 'names' ); + $expected = array( 'wptests_tax' ); + + $this->assertSame( $expected, $found ); + } + + public function test_should_return_taxonomy_registered_for_specific_file_extension() { + register_taxonomy( 'wptests_tax', 'attachment:jpg' ); + + $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment' + ) ); + $attachment = get_post( $a ); + + $found = get_attachment_taxonomies( $attachment, 'names' ); + $expected = array( 'wptests_tax' ); + + $this->assertSame( $expected, $found ); + } + + public function test_should_not_return_duplicate_taxonomies() { + register_taxonomy( 'wptests_tax', array( 'attachment', 'attachment:image/jpeg' ) ); + + $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment' + ) ); + $attachment = get_post( $a ); + + $found = get_attachment_taxonomies( $attachment, 'names' ); + $expected = array( 'wptests_tax' ); + + $this->assertSame( $expected, $found ); + } +}