| 407 | |
| 408 | /** |
| 409 | * @ticket 39231 |
| 410 | */ |
| 411 | public function test_fallback_intermediate_image_sizes() { |
| 412 | if ( ! wp_image_editor_supports( array( 'mime_type' => 'application/pdf' ) ) ) { |
| 413 | $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' ); |
| 414 | } |
| 415 | |
| 416 | $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf'; |
| 417 | $test_file = '/tmp/wordpress-gsoc-flyer.pdf'; |
| 418 | copy( $orig_file, $test_file ); |
| 419 | |
| 420 | $attachment_id = $this->factory->attachment->create_object( $test_file, 0, array( |
| 421 | 'post_mime_type' => 'application/pdf', |
| 422 | ) ); |
| 423 | |
| 424 | $this->assertNotEmpty( $attachment_id ); |
| 425 | |
| 426 | add_image_size( 'test-size', 100, 100 ); |
| 427 | add_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10, 2 ); |
| 428 | |
| 429 | $expected = array( |
| 430 | 'sizes' => array( |
| 431 | 'thumbnail' => array( |
| 432 | 'file' => "wordpress-gsoc-flyer-116x150.jpg", |
| 433 | 'width' => 116, |
| 434 | 'height' => 150, |
| 435 | 'mime-type' => "image/jpeg", |
| 436 | ), |
| 437 | 'medium' => array( |
| 438 | 'file' => "wordpress-gsoc-flyer-232x300.jpg", |
| 439 | 'width' => 232, |
| 440 | 'height' => 300, |
| 441 | 'mime-type' => "image/jpeg", |
| 442 | ), |
| 443 | 'test-size' => array( |
| 444 | 'file' => "wordpress-gsoc-flyer-77x100.jpg", |
| 445 | 'width' => 77, |
| 446 | 'height' => 100, |
| 447 | 'mime-type' => "image/jpeg", |
| 448 | ), |
| 449 | 'full' => array( |
| 450 | 'file' => "wordpress-gsoc-flyer.jpg", |
| 451 | 'width' => 1088, |
| 452 | 'height' => 1408, |
| 453 | 'mime-type' => "image/jpeg", |
| 454 | ), |
| 455 | ), |
| 456 | ); |
| 457 | |
| 458 | $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file ); |
| 459 | $this->assertSame( $expected, $metadata ); |
| 460 | |
| 461 | remove_image_size( 'test-size' ); |
| 462 | remove_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10 ); |
| 463 | |
| 464 | unlink( $test_file ); |
| 465 | } |
| 466 | |
| 467 | function filter_fallback_intermediate_image_sizes( $fallback_sizes, $metadata ) { |
| 468 | if ( false !== ( $idx = array_search( 'large', $fallback_sizes, true ) ) ) { |
| 469 | $fallback_sizes[ $idx ] = 'test-size'; |
| 470 | } |
| 471 | return $fallback_sizes; |
| 472 | } |