Changeset 53541
- Timestamp:
- 06/20/2022 10:04:24 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/functions.php
r53538 r53541 484 484 485 485 /** 486 * @ticket 55403487 * @covers ::wp_crop_image488 */489 public function test_wp_crop_image_with_filtered_extension() {490 add_filter( 'image_editor_output_format', array( $this, 'filter_image_editor_output_format' ) );491 $file = wp_crop_image(492 DIR_TESTDATA . '/images/canola.jpg',493 0,494 0,495 100,496 100,497 100,498 100499 );500 501 $this->assertNotWPError( $file );502 $this->assertFileExists( $file );503 504 unlink( $file );505 }506 507 public function filter_image_editor_output_format() {508 return array_fill_keys( array( 'image/jpg', 'image/jpeg', 'image/png' ), 'image/webp' );509 }510 511 /**512 486 * @covers ::wp_crop_image 513 487 * @requires function imagejpeg 514 488 */ 515 public function test_wp_crop_image_ file() {489 public function test_wp_crop_image_with_file() { 516 490 $file = wp_crop_image( 517 491 DIR_TESTDATA . '/images/canola.jpg', … … 540 514 * @requires extension openssl 541 515 */ 542 public function test_wp_crop_image_ url() {516 public function test_wp_crop_image_with_url() { 543 517 $file = wp_crop_image( 544 518 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg', … … 572 546 * @covers ::wp_crop_image 573 547 */ 574 public function test_wp_crop_image_ file_not_exists() {548 public function test_wp_crop_image_should_fail_with_wp_error_object_if_file_does_not_exists() { 575 549 $file = wp_crop_image( 576 550 DIR_TESTDATA . '/images/canoladoesnotexist.jpg', … … 589 563 * @requires extension openssl 590 564 */ 591 public function test_wp_crop_image_ url_not_exists() {565 public function test_wp_crop_image_should_fail_with_wp_error_object_if_url_does_not_exist() { 592 566 $file = wp_crop_image( 593 567 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg', … … 606 580 * @covers ::wp_crop_image 607 581 */ 608 public function test_wp_crop_image_ error_on_saving() {582 public function test_wp_crop_image_should_fail_with_wp_error_object_if_there_was_an_error_on_saving() { 609 583 WP_Image_Editor_Mock::$save_return = new WP_Error(); 610 add_filter( 'wp_image_editors', array( $this, 'mock_image_editor' ) ); 584 585 add_filter( 586 'wp_image_editors', 587 static function( $editors ) { 588 return array( 'WP_Image_Editor_Mock' ); 589 } 590 ); 611 591 612 592 $file = wp_crop_image( … … 621 601 $this->assertInstanceOf( 'WP_Error', $file ); 622 602 623 remove_filter( 'wp_image_editors', array( $this, 'mock_image_editor' ) );624 603 WP_Image_Editor_Mock::$save_return = array(); 625 604 } 626 605 627 606 /** 628 * @see test_wp_crop_image_error_on_saving() 629 */ 630 public function mock_image_editor( $editors ) { 631 return array( 'WP_Image_Editor_Mock' ); 607 * @ticket 55403 608 * @covers ::wp_crop_image 609 */ 610 public function test_wp_crop_image_should_return_correct_file_extension_if_output_format_was_modified() { 611 add_filter( 612 'image_editor_output_format', 613 static function() { 614 return array_fill_keys( array( 'image/jpg', 'image/jpeg', 'image/png' ), 'image/webp' ); 615 } 616 ); 617 618 $file = wp_crop_image( 619 DIR_TESTDATA . '/images/canola.jpg', 620 0, 621 0, 622 100, 623 100, 624 100, 625 100 626 ); 627 628 $this->assertNotWPError( $file, 'Cropping the image resulted in a WP_Error.' ); 629 $this->assertFileExists( $file, "The file $file does not exist." ); 630 631 unlink( $file ); 632 632 } 633 633
Note: See TracChangeset
for help on using the changeset viewer.