Make WordPress Core

Ticket #30017: get_attachment_taxonomies.patch

File get_attachment_taxonomies.patch, 5.0 KB (added by Frank Klein, 6 years ago)
  • tests/phpunit/tests/media/getAttachmentTaxonomies.php

    diff --git tests/phpunit/tests/media/getAttachmentTaxonomies.php tests/phpunit/tests/media/getAttachmentTaxonomies.php
    index c78ce6aa81..ae6735a701 100644
     
    55 * @group taxonomy
    66 */
    77class 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
    825        public function test_should_return_attachment_taxonomy() {
    926                register_taxonomy( 'wptests_tax', 'attachment' );
    1027
    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' ) );
    2129        }
    2230
    2331        public function test_should_return_taxonomy_registered_for_specific_attachment_type() {
    2432                register_taxonomy( 'wptests_tax', 'attachment:image' );
    2533
    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' ) );
    3635        }
    3736
    3837        public function test_should_return_taxonomy_registered_for_specific_attachment_mimetype() {
    3938                register_taxonomy( 'wptests_tax', 'attachment:image/jpeg' );
    4039
    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' ) );
    5141        }
    5242
    5343        public function test_should_return_taxonomy_registered_for_specific_file_extension() {
    5444                register_taxonomy( 'wptests_tax', 'attachment:jpg' );
    5545
    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' ) );
    6647        }
    6748
    6849        public function test_should_not_return_duplicate_taxonomies() {
    6950                register_taxonomy( 'wptests_tax', array( 'attachment', 'attachment:image/jpeg' ) );
    7051
    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' ) );
    8153        }
    8254
    8355        /**
    class Tests_Media_GetAttachmentTaxonomies extends WP_UnitTestCase { 
    8658        public function test_should_respect_output_objects() {
    8759                register_taxonomy( 'wptests_tax2', 'attachment:image' );
    8860
    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' );
    9662
    9763                $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
    9864                $this->assertInternalType( 'object', $found['wptests_tax2'] );
    9965                $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name );
    10066        }
    10167
    102 
    10368        /**
    10469         * @ticket 37368
    10570         */
    10671        public function test_should_return_unique_taxonomies_for_output_objects() {
    10772                register_taxonomy( 'wptests_tax2', array( 'attachment:image', 'attachment:image/jpeg' ) );
    10873
    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' );
    11675
    11776                $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
    11877                $this->assertInternalType( 'object', $found['wptests_tax2'] );