Files
wordpress-develop/tests/phpunit/tests/media/getAttachmentTaxonomies.php
T
Gary Pendergast a75d153eee Coding Standards: Upgrade WPCS to 1.0.0
WPCS 1.0.0 includes a bunch of new auto-fixers, which drops the number of coding standards issues across WordPress significantly. Prior to running the auto-fixers, there were 15,312 issues detected. With this commit, we now drop to 4,769 issues.

This change includes three notable additions:
- Multiline function calls must now put each parameter on a new line.
- Auto-formatting files is now part of the `grunt precommit` script. 
- Auto-fixable coding standards issues will now cause Travis failures.

Fixes #44600.



git-svn-id: https://develop.svn.wordpress.org/trunk@43571 602fd350-edb4-49c9-b593-d223f7449a82
2018-08-17 01:50:26 +00:00

150 lines
3.9 KiB
PHP

<?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 );
}
/**
* @ticket 37368
*/
public function test_should_respect_output_objects() {
register_taxonomy( 'wptests_tax2', '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, 'objects' );
$this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
$this->assertInternalType( 'object', $found['wptests_tax2'] );
$this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name );
}
/**
* @ticket 37368
*/
public function test_should_return_unique_taxonomies_for_output_objects() {
register_taxonomy( 'wptests_tax2', array( 'attachment:image', '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, 'objects' );
$this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
$this->assertInternalType( 'object', $found['wptests_tax2'] );
$this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name );
}
}