Changeset 51415 for trunk/tests/phpunit/tests/image/functions.php
- Timestamp:
- 07/13/2021 10:43:42 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/functions.php
r51397 r51415 173 173 */ 174 174 public function test_wp_save_image_file() { 175 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 176 177 foreach ( $classes as $key => $class ) { 178 if ( ! call_user_func( array( $class, 'test' ) ) ) { 179 // If the image editor isn't available, skip it. 180 unset( $classes[ $key ] ); 181 } 182 } 183 184 if ( ! $classes ) { 185 $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) ); 186 } 175 $classes = $this->get_image_editor_engine_classes(); 187 176 188 177 require_once ABSPATH . 'wp-admin/includes/image-edit.php'; … … 234 223 */ 235 224 public function test_mime_overrides_filename() { 236 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 237 238 foreach ( $classes as $key => $class ) { 239 if ( ! call_user_func( array( $class, 'test' ) ) ) { 240 // If the image editor isn't available, skip it. 241 unset( $classes[ $key ] ); 242 } 243 } 244 245 if ( ! $classes ) { 246 $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) ); 247 } 225 $classes = $this->get_image_editor_engine_classes(); 248 226 249 227 // Test each image editor engine. … … 276 254 */ 277 255 public function test_inferred_mime_types() { 278 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 279 280 foreach ( $classes as $key => $class ) { 281 if ( ! call_user_func( array( $class, 'test' ) ) ) { 282 // If the image editor isn't available, skip it. 283 unset( $classes[ $key ] ); 284 } 285 } 286 287 if ( ! $classes ) { 288 $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) ); 289 } 256 $classes = $this->get_image_editor_engine_classes(); 290 257 291 258 // Mime types. … … 343 310 $this->assertInstanceOf( 'WP_Error', $editor2 ); 344 311 312 $classes = $this->get_image_editor_engine_classes(); 313 314 // Then, test with editors. 315 foreach ( $classes as $class ) { 316 $editor = new $class( DIR_TESTDATA ); 317 $loaded = $editor->load(); 318 319 $this->assertInstanceOf( 'WP_Error', $loaded ); 320 $this->assertSame( 'error_loading_image', $loaded->get_error_code() ); 321 } 322 } 323 324 /** 325 * Get the available image editor engine class(es). 326 * 327 * @return string[] Available image editor classes; empty array when none are avaialble. 328 */ 329 private function get_image_editor_engine_classes() { 345 330 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 346 331 … … 352 337 } 353 338 354 if ( ! $classes ) { 355 $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) ); 356 } 357 358 // Then, test with editors. 359 foreach ( $classes as $class ) { 360 $editor = new $class( DIR_TESTDATA ); 361 $loaded = $editor->load(); 362 363 $this->assertInstanceOf( 'WP_Error', $loaded ); 364 $this->assertSame( 'error_loading_image', $loaded->get_error_code() ); 365 } 339 if ( empty( $classes ) ) { 340 $this->markTestSkipped( 'Image editor engines WP_Image_Editor_GD and WP_Image_Editor_Imagick are not supported on this system.' ); 341 } 342 343 return $classes; 366 344 } 367 345
Note: See TracChangeset
for help on using the changeset viewer.