Introduce tests for get_attachment_taxonomies().

See #37368.

git-svn-id: https://develop.svn.wordpress.org/trunk@38291 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-08-20 17:24:12 +00:00
parent 86a2c06f6f
commit 773eb46bf8

View File

@@ -0,0 +1,82 @@
<?php
/**
* @group media
* @group taxonomy
*/
class Tests_Media_GetAttachmentTaxonomies extends WP_UnitTestCase {
public function test_should_return_attachment_taxonomy() {
register_taxonomy( 'wptests_tax', 'attachment' );
$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_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 );
}
}