Changeset 50771
- Timestamp:
- 04/20/2021 03:01:55 AM (4 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/class-wp-test-stream.php
r49545 r50771 12 12 * (note the trailing slash). 13 13 * 14 * This class can be used to test that code works with basic read/write streams, 15 * as such, operations such as seeking are not supported. 14 * This class can be used to test that code works with basic read/write streams. 16 15 * 17 16 * This class does not register itself as a stream handler: test fixtures … … 25 24 * In-memory storage for files and directories simulated by this wrapper. 26 25 */ 27 static $data = array();28 29 var$position;30 var$file;31 var$bucket;32 var$data_ref;26 public static $data = array(); 27 28 public $position; 29 public $file; 30 public $bucket; 31 public $data_ref; 33 32 34 33 /** … … 67 66 * @see streamWrapper::stream_open 68 67 */ 69 function stream_open( $path, $mode, $options, &$opened_path ) {68 public function stream_open( $path, $mode, $options, &$opened_path ) { 70 69 $this->open( $path ); 71 70 return true; … … 77 76 * @see streamWrapper::stream_read 78 77 */ 79 function stream_read( $count ) {78 public function stream_read( $count ) { 80 79 if ( ! isset( $this->data_ref ) ) { 81 80 return ''; … … 93 92 * @see streamWrapper::stream_write 94 93 */ 95 function stream_write( $data ) {94 public function stream_write( $data ) { 96 95 if ( ! isset( $this->data_ref ) ) { 97 96 $this->data_ref = ''; … … 108 107 109 108 /** 109 * Seeks to specific location in a stream. 110 * 111 * @see streamWrapper::stream_seek 112 * 113 * @param int $offset The stream offset to seek to. 114 * @param int $whence Optional. Seek position. 115 * @return bool Returns true when position is updated, else false. 116 */ 117 public function stream_seek( $offset, $whence = SEEK_SET ) { 118 if ( empty( $this->data_ref ) ) { 119 return false; 120 } 121 122 $new_offset = $this->position; 123 switch ( $whence ) { 124 case SEEK_CUR: 125 $new_offset += $offset; 126 break; 127 128 case SEEK_END: 129 $new_offset = strlen( $this->data_ref ) + $offset; 130 break; 131 132 case SEEK_SET: 133 $new_offset = $offset; 134 break; 135 136 default: 137 return false; 138 } 139 140 if ( $new_offset < 0 ) { 141 return false; 142 } 143 144 // Save the new position. 145 $this->position = $new_offset; 146 147 return true; 148 } 149 150 /** 110 151 * Retrieves the current position of a stream. 111 152 * 112 153 * @see streamWrapper::stream_tell 113 154 */ 114 function stream_tell() {155 public function stream_tell() { 115 156 return $this->position; 116 157 } … … 121 162 * @see streamWrapper::stream_eof 122 163 */ 123 function stream_eof() {164 public function stream_eof() { 124 165 if ( ! isset( $this->data_ref ) ) { 125 166 return true; … … 134 175 * @see streamWrapper::stream_metadata 135 176 */ 136 function stream_metadata( $path, $option, $var ) {177 public function stream_metadata( $path, $option, $var ) { 137 178 $this->open( $path ); 138 179 if ( STREAM_META_TOUCH === $option ) { … … 150 191 * @see streamWrapper::mkdir 151 192 */ 152 function mkdir( $path, $mode, $options ) {193 public function mkdir( $path, $mode, $options ) { 153 194 $this->open( $path ); 154 195 $plainfile = rtrim( $this->file, '/' ); -
trunk/tests/phpunit/tests/image/meta.php
r49025 r50771 7 7 * @requires extension gd 8 8 * @requires extension exif 9 * 10 * @covers ::wp_read_image_metadata 9 11 */ 10 12 class 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 } 11 30 12 31 function test_exif_d70() { … … 151 170 } 152 171 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 } 153 242 }
Note: See TracChangeset
for help on using the changeset viewer.