Ticket #39875: 39875.patch
File 39875.patch, 5.0 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-image-editor-imagick.php
624 624 protected function _save( $image, $filename = null, $mime_type = null ) { 625 625 list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); 626 626 627 if ( ! $filename ) 627 if ( ! $filename ) { 628 628 $filename = $this->generate_filename( null, null, $extension ); 629 } else { 630 // If PDF preview. 631 if ( 'image/jpeg' === $mime_type && 'pdf' === strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ) ) { 632 // Make sure not to overwrite existing JPEG with same name. 633 $dirname = dirname( $filename ); 634 $filename = $dirname . '/' . wp_unique_filename( $dirname, wp_basename( $filename ) ); 635 } 636 } 629 637 630 638 try { 631 639 // Store initial Format -
tests/phpunit/tests/image/editor_imagick.php
542 542 543 543 $this->assertTrue( $result ); 544 544 } 545 546 /** 547 * Test PDF preview doesn't overwrite existing JPEG. 548 * @ticket 39875 549 */ 550 public function test_pdf_preview_doesnt_overwrite_existing_jpeg() { 551 // Dummy JPEG. 552 $jpg_path = '/tmp/test.jpg'; 553 file_put_contents( $jpg_path, 'asdf' ); 554 555 // PDF with same name as JPEG. 556 $pdf_path = '/tmp/test.pdf'; 557 copy( DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf', $pdf_path ); 558 559 // Load PDF. 560 $image_editor = new WP_Image_Editor_Imagick( $pdf_path ); 561 $output = $image_editor->load(); 562 $this->assertTrue( $output ); 563 564 // Create PDF preview. 565 $output = $image_editor->save( $pdf_path, 'image/jpeg' ); 566 567 $this->assertNotEmpty( $output ); 568 $this->assertTrue( is_array( $output ) ); 569 $this->assertNotEquals( $jpg_path, $output['path'] ); 570 $this->assertNotEquals( $pdf_path, $output['path'] ); 571 $this->assertSame( 'asdf', file_get_contents( $jpg_path ) ); 572 $this->assertTrue( is_file( $output['path'] ) ); 573 $this->assertSame( wp_basename( $output['path'] ), $output['file'] ); 574 $this->assertSame( 'image/jpeg', $output['mime-type'] ); 575 576 // Cleanup. 577 unlink( $jpg_path ); 578 unlink( $pdf_path ); 579 unlink( $output['path'] ); 580 } 545 581 } -
tests/phpunit/tests/image/functions.php
18 18 require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' ); 19 19 20 20 include_once( DIR_TESTDATA . '/../includes/mock-image-editor.php' ); 21 22 $folder = '/tmp/wordpress-gsoc-flyer*.jpg'; 23 24 foreach ( glob( $folder ) as $file ) { 25 unlink( $file ); 26 } 21 27 } 22 28 23 29 /** … … 403 409 $this->assertSame( $expected, $metadata ); 404 410 405 411 unlink( $test_file ); 412 foreach ( $expected['sizes'] as $size ) { 413 unlink ( '/tmp/' . $size['file'] ); 414 } 406 415 } 407 416 408 417 /** … … 427 436 add_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10, 2 ); 428 437 429 438 $expected = array( 430 'file' => 'wordpress-gsoc-flyer-77x100.jpg',431 'width' => 77,432 'height' => 100,433 'mime-type' => 'image/jpeg',434 439 ); 440 $expected = array( 441 'sizes' => array( 442 'thumbnail' => array( 443 'file' => "wordpress-gsoc-flyer-116x150.jpg", 444 'width' => 116, 445 'height' => 150, 446 'mime-type' => "image/jpeg", 447 ), 448 'medium' => array( 449 'file' => "wordpress-gsoc-flyer-232x300.jpg", 450 'width' => 232, 451 'height' => 300, 452 'mime-type' => "image/jpeg", 453 ), 454 'large' => array( 455 'file' => "wordpress-gsoc-flyer-791x1024.jpg", 456 'width' => 791, 457 'height' => 1024, 458 'mime-type' => "image/jpeg", 459 ), 460 'test-size' => array( 461 'file' => 'wordpress-gsoc-flyer-77x100.jpg', 462 'width' => 77, 463 'height' => 100, 464 'mime-type' => 'image/jpeg', 465 ), 466 'full' => array( 467 'file' => "wordpress-gsoc-flyer.jpg", 468 'width' => 1088, 469 'height' => 1408, 470 'mime-type' => "image/jpeg", 471 ), 472 ), 473 ); 435 474 436 475 $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file ); 437 476 $this->assertTrue( isset( $metadata['sizes']['test-size'] ), 'The `test-size` was not added to the metadata.' ); 438 $this->assertSame( $ metadata['sizes']['test-size'], $expected);477 $this->assertSame( $expected, $metadata ); 439 478 440 479 remove_image_size( 'test-size' ); 441 480 remove_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10 ); 442 481 443 482 unlink( $test_file ); 483 foreach ( $expected['sizes'] as $size ) { 484 unlink ( '/tmp/' . $size['file'] ); 485 } 444 486 } 445 487 446 488 function filter_fallback_intermediate_image_sizes( $fallback_sizes, $metadata ) {