Make WordPress Core


Ignore:
Timestamp:
04/20/2021 03:01:55 AM (5 years ago)
Author:
peterwilsoncc
Message:

Build/Test Tools: Add seeking support to stream test library.

Introduces seeking to the WP_Test_Stream stream wrapper. This allows the testing of wp_getimagesize() and wp_read_image_metadata() among others. Includes tests for the latter.

Props hellofromTonya.
Fixes #52922.
See #52826.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/meta.php

    r49025 r50771  
    77 * @requires extension gd
    88 * @requires extension exif
     9 *
     10 * @covers ::wp_read_image_metadata
    911 */
    1012class Tests_Image_Meta extends WP_UnitTestCase {
     13
     14        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     15                require_once DIR_TESTROOT . '/includes/class-wp-test-stream.php';
     16                stream_wrapper_register( 'testimagemeta', 'WP_Test_Stream' );
     17
     18                WP_Test_Stream::$data = array(
     19                        'wp_read_image_metadata' => array(
     20                                '/image1.jpg' => file_get_contents( DIR_TESTDATA . '/images/test-image-upside-down.jpg' ),
     21                                '/image2.jpg' => file_get_contents( DIR_TESTDATA . '/images/2004-07-22-DSC_0007.jpg' ),
     22                                '/image3.jpg' => file_get_contents( DIR_TESTDATA . '/images/33772.jpg' ),
     23                        ),
     24                );
     25        }
     26
     27        public static function wpTearDownAfterClass() {
     28                stream_wrapper_unregister( 'testimagemeta' );
     29        }
    1130
    1231        function test_exif_d70() {
    … …  
    151170        }
    152171
     172        /**
     173         * @dataProvider data_stream
     174         *
     175         * @ticket 52826
     176         * @ticket 52922
     177         *
     178         * @param string Stream's URI.
     179         * @param array  Expected metadata.
     180         */
     181        public function test_stream( $file, $expected ) {
     182                $actual = wp_read_image_metadata( $file );
     183
     184                $this->assertSame( $expected, $actual );
     185        }
     186
     187        public function data_stream() {
     188                return array(
     189                        'Orientation only metadata'                => array(
     190                                'file'     => 'testimagemeta://wp_read_image_metadata/image1.jpg',
     191                                'metadata' => array(
     192                                        'aperture'          => '0',
     193                                        'credit'            => '',
     194                                        'camera'            => '',
     195                                        'caption'           => '',
     196                                        'created_timestamp' => '0',
     197                                        'copyright'         => '',
     198                                        'focal_length'      => '0',
     199                                        'iso'               => '0',
     200                                        'shutter_speed'     => '0',
     201                                        'title'             => '',
     202                                        'orientation'       => '3',
     203                                        'keywords'          => array(),
     204                                ),
     205                        ),
     206                        'Exif from a Nikon D70 with IPTC data added later' => array(
     207                                'file'     => 'testimagemeta://wp_read_image_metadata/image2.jpg',
     208                                'metadata' => array(
     209                                        'aperture'          => '6.3',
     210                                        'credit'            => 'IPTC Creator',
     211                                        'camera'            => 'NIKON D70',
     212                                        'caption'           => 'IPTC Caption',
     213                                        'created_timestamp' => '1090516475',
     214                                        'copyright'         => 'IPTC Copyright',
     215                                        'focal_length'      => '18',
     216                                        'iso'               => '200',
     217                                        'shutter_speed'     => '0.04',
     218                                        'title'             => 'IPTC Headline',
     219                                        'orientation'       => '0',
     220                                        'keywords'          => array(),
     221                                ),
     222                        ),
     223                        'Exif from a DMC-LX2 camera with keywords' => array(
     224                                'file'     => 'testimagemeta://wp_read_image_metadata/image3.jpg',
     225                                'metadata' => array(
     226                                        'aperture'          => '8',
     227                                        'credit'            => 'Photoshop Author',
     228                                        'camera'            => 'DMC-LX2',
     229                                        'caption'           => 'Photoshop Description',
     230                                        'created_timestamp' => '1306315327',
     231                                        'copyright'         => 'Photoshop Copyrright Notice',
     232                                        'focal_length'      => '6.3',
     233                                        'iso'               => '100',
     234                                        'shutter_speed'     => '0.0025',
     235                                        'title'             => 'Photoshop Document Ttitle',
     236                                        'orientation'       => '1',
     237                                        'keywords'          => array( 'beach', 'baywatch', 'LA', 'sunset' ),
     238                                ),
     239                        ),
     240                );
     241        }
    153242}
Note: See TracChangeset for help on using the changeset viewer.