diff --git tests/phpunit/tests/media/getAttachmentTaxonomies.php tests/phpunit/tests/media/getAttachmentTaxonomies.php
index c78ce6aa81..ae6735a701 100644
|
|
|
5 | 5 | * @group taxonomy |
6 | 6 | */ |
7 | 7 | class Tests_Media_GetAttachmentTaxonomies extends WP_UnitTestCase { |
| 8 | /** |
| 9 | * Instance of a JPEG image attachment. |
| 10 | * |
| 11 | * @var WP_Post; |
| 12 | */ |
| 13 | public static $attachment; |
| 14 | |
| 15 | public static function wpSetUpBeforeClass( $factory ) { |
| 16 | self::$attachment = get_post( |
| 17 | $factory->attachment->create_object( array( |
| 18 | 'file' => 'image.jpg', |
| 19 | 'post_mime_type' => 'image/jpeg', |
| 20 | 'post_type' => 'attachment', |
| 21 | ) ) |
| 22 | ); |
| 23 | } |
| 24 | |
8 | 25 | public function test_should_return_attachment_taxonomy() { |
9 | 26 | register_taxonomy( 'wptests_tax', 'attachment' ); |
10 | 27 | |
11 | | $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( |
12 | | 'post_mime_type' => 'image/jpeg', |
13 | | 'post_type' => 'attachment' |
14 | | ) ); |
15 | | $attachment = get_post( $a ); |
16 | | |
17 | | $found = get_attachment_taxonomies( $attachment, 'names' ); |
18 | | $expected = array( 'wptests_tax' ); |
19 | | |
20 | | $this->assertSame( $expected, $found ); |
| 28 | $this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) ); |
21 | 29 | } |
22 | 30 | |
23 | 31 | public function test_should_return_taxonomy_registered_for_specific_attachment_type() { |
24 | 32 | register_taxonomy( 'wptests_tax', 'attachment:image' ); |
25 | 33 | |
26 | | $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( |
27 | | 'post_mime_type' => 'image/jpeg', |
28 | | 'post_type' => 'attachment' |
29 | | ) ); |
30 | | $attachment = get_post( $a ); |
31 | | |
32 | | $found = get_attachment_taxonomies( $attachment, 'names' ); |
33 | | $expected = array( 'wptests_tax' ); |
34 | | |
35 | | $this->assertSame( $expected, $found ); |
| 34 | $this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) ); |
36 | 35 | } |
37 | 36 | |
38 | 37 | public function test_should_return_taxonomy_registered_for_specific_attachment_mimetype() { |
39 | 38 | register_taxonomy( 'wptests_tax', 'attachment:image/jpeg' ); |
40 | 39 | |
41 | | $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( |
42 | | 'post_mime_type' => 'image/jpeg', |
43 | | 'post_type' => 'attachment' |
44 | | ) ); |
45 | | $attachment = get_post( $a ); |
46 | | |
47 | | $found = get_attachment_taxonomies( $attachment, 'names' ); |
48 | | $expected = array( 'wptests_tax' ); |
49 | | |
50 | | $this->assertSame( $expected, $found ); |
| 40 | $this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) ); |
51 | 41 | } |
52 | 42 | |
53 | 43 | public function test_should_return_taxonomy_registered_for_specific_file_extension() { |
54 | 44 | register_taxonomy( 'wptests_tax', 'attachment:jpg' ); |
55 | 45 | |
56 | | $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( |
57 | | 'post_mime_type' => 'image/jpeg', |
58 | | 'post_type' => 'attachment' |
59 | | ) ); |
60 | | $attachment = get_post( $a ); |
61 | | |
62 | | $found = get_attachment_taxonomies( $attachment, 'names' ); |
63 | | $expected = array( 'wptests_tax' ); |
64 | | |
65 | | $this->assertSame( $expected, $found ); |
| 46 | $this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) ); |
66 | 47 | } |
67 | 48 | |
68 | 49 | public function test_should_not_return_duplicate_taxonomies() { |
69 | 50 | register_taxonomy( 'wptests_tax', array( 'attachment', 'attachment:image/jpeg' ) ); |
70 | 51 | |
71 | | $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( |
72 | | 'post_mime_type' => 'image/jpeg', |
73 | | 'post_type' => 'attachment' |
74 | | ) ); |
75 | | $attachment = get_post( $a ); |
76 | | |
77 | | $found = get_attachment_taxonomies( $attachment, 'names' ); |
78 | | $expected = array( 'wptests_tax' ); |
79 | | |
80 | | $this->assertSame( $expected, $found ); |
| 52 | $this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) ); |
81 | 53 | } |
82 | 54 | |
83 | 55 | /** |
… |
… |
class Tests_Media_GetAttachmentTaxonomies extends WP_UnitTestCase { |
86 | 58 | public function test_should_respect_output_objects() { |
87 | 59 | register_taxonomy( 'wptests_tax2', 'attachment:image' ); |
88 | 60 | |
89 | | $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( |
90 | | 'post_mime_type' => 'image/jpeg', |
91 | | 'post_type' => 'attachment' |
92 | | ) ); |
93 | | $attachment = get_post( $a ); |
94 | | |
95 | | $found = get_attachment_taxonomies( $attachment, 'objects' ); |
| 61 | $found = get_attachment_taxonomies( self::$attachment, 'objects' ); |
96 | 62 | |
97 | 63 | $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) ); |
98 | 64 | $this->assertInternalType( 'object', $found['wptests_tax2'] ); |
99 | 65 | $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name ); |
100 | 66 | } |
101 | 67 | |
102 | | |
103 | 68 | /** |
104 | 69 | * @ticket 37368 |
105 | 70 | */ |
106 | 71 | public function test_should_return_unique_taxonomies_for_output_objects() { |
107 | 72 | register_taxonomy( 'wptests_tax2', array( 'attachment:image', 'attachment:image/jpeg' ) ); |
108 | 73 | |
109 | | $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( |
110 | | 'post_mime_type' => 'image/jpeg', |
111 | | 'post_type' => 'attachment' |
112 | | ) ); |
113 | | $attachment = get_post( $a ); |
114 | | |
115 | | $found = get_attachment_taxonomies( $attachment, 'objects' ); |
| 74 | $found = get_attachment_taxonomies( self::$attachment, 'objects' ); |
116 | 75 | |
117 | 76 | $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) ); |
118 | 77 | $this->assertInternalType( 'object', $found['wptests_tax2'] ); |