Changeset 54401 for trunk/tests/phpunit/tests/image/editorImagick.php
- Timestamp:
- 10/07/2022 12:40:07 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/editorImagick.php
r54226 r54401 36 36 37 37 /** 38 * Checksupport for ImageMagick compatible mime types.38 * Tests support for ImageMagick compatible mime types. 39 39 */ 40 40 public function test_supports_mime_type() { … … 47 47 48 48 /** 49 * Test resizing an image, not using crop49 * Tests resizing an image, not using crop. 50 50 */ 51 51 public function test_resize() { … … 67 67 68 68 /** 69 * Test multi_resize with single image resize and no crop69 * Tests multi_resize() with single image resize and no crop. 70 70 */ 71 71 public function test_single_multi_resize() { … … 107 107 108 108 /** 109 * Ensure multi_resize doesn't create an image when109 * Tests that multi_resize() does not create an image when 110 110 * both height and weight are missing, null, or 0. 111 111 * … … 176 176 177 177 /** 178 * Test multi_resize with multiple sizes178 * Tests multi_resize() with multiple sizes. 179 179 * 180 180 * @ticket 26823 … … 188 188 $sizes_array = array( 189 189 190 /* *190 /* 191 191 * #0 - 10x10 resize, no cropping. 192 192 * By aspect, should be 10x6 output. … … 198 198 ), 199 199 200 /* *200 /* 201 201 * #1 - 75x50 resize, with cropping. 202 202 * Output dimensions should be 75x50 … … 208 208 ), 209 209 210 /* *210 /* 211 211 * #2 - 20 pixel max height, no cropping. 212 212 * By aspect, should be 30x20 output. … … 218 218 ), 219 219 220 /* *220 /* 221 221 * #3 - 45 pixel max height, with cropping. 222 222 * By aspect, should be 45x400 output. … … 228 228 ), 229 229 230 /* *230 /* 231 231 * #4 - 50 pixel max width, no cropping. 232 232 * By aspect, should be 50x33 output. … … 236 236 ), 237 237 238 /* *238 /* 239 239 * #5 - 55 pixel max width, no cropping, null height 240 240 * By aspect, should be 55x36 output. … … 245 245 ), 246 246 247 /* *247 /* 248 248 * #6 - 55 pixel max height, no cropping, no width specified. 249 249 * By aspect, should be 82x55 output. … … 253 253 ), 254 254 255 /* *255 /* 256 256 * #7 - 60 pixel max height, no cropping, null width. 257 257 * By aspect, should be 90x60 output. … … 262 262 ), 263 263 264 /* *264 /* 265 265 * #8 - 70 pixel max height, no cropping, negative width. 266 266 * By aspect, should be 105x70 output. … … 271 271 ), 272 272 273 /* *273 /* 274 274 * #9 - 200 pixel max width, no cropping, negative height. 275 275 * By aspect, should be 200x133 output. … … 392 392 393 393 /** 394 * Test resizing an image with cropping394 * Tests resizing an image with cropping. 395 395 */ 396 396 public function test_resize_and_crop() { … … 412 412 413 413 /** 414 * Test cropping an image414 * Tests cropping an image. 415 415 */ 416 416 public function test_crop() { … … 432 432 433 433 /** 434 * Test rotating an image 180 deg434 * Tests rotating an image 180 deg. 435 435 */ 436 436 public function test_rotate() { … … 451 451 452 452 /** 453 * Test flipping an image453 * Tests flipping an image. 454 454 */ 455 455 public function test_flip() { … … 470 470 471 471 /** 472 * Test the image created with WP_Image_Editor_Imagick preserves alpha when resizing472 * Tests that an image created with WP_Image_Editor_Imagick preserves alpha with no resizing. 473 473 * 474 474 * @ticket 24871 475 475 */ 476 public function test_image_preserves_alpha _on_resize() {476 public function test_image_preserves_alpha() { 477 477 $file = DIR_TESTDATA . '/images/transparent.png'; 478 478 479 $ editor = new WP_Image_Editor_Imagick( $file );480 $ editor->load();481 $editor->resize( 5, 5 ); 479 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 480 $imagick_image_editor->load(); 481 482 482 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 483 483 484 $ editor->save( $save_to_file );484 $imagick_image_editor->save( $save_to_file ); 485 485 486 486 $im = new Imagick( $save_to_file ); … … 494 494 495 495 /** 496 * Test the image created with WP_Image_Editor_Imagick preserves alpha with no resizing etc496 * Tests that an image created with WP_Image_Editor_Imagick preserves alpha when resizing. 497 497 * 498 498 * @ticket 24871 499 499 */ 500 public function test_image_preserves_alpha () {500 public function test_image_preserves_alpha_on_resize() { 501 501 $file = DIR_TESTDATA . '/images/transparent.png'; 502 502 503 $editor = new WP_Image_Editor_Imagick( $file ); 504 $editor->load(); 505 503 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 504 $imagick_image_editor->load(); 505 506 $imagick_image_editor->resize( 5, 5 ); 506 507 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 507 508 508 $ editor->save( $save_to_file );509 $imagick_image_editor->save( $save_to_file ); 509 510 510 511 $im = new Imagick( $save_to_file ); … … 526 527 $pre_rotate_pixel = $pre_rotate_editor->getImagePixelColor( 0, 0 ); 527 528 $pre_rotate_alpha = $pre_rotate_pixel->getColorValue( imagick::COLOR_ALPHA ); 528 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 529 530 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 529 531 $pre_rotate_editor->writeImage( $save_to_file ); 530 532 $pre_rotate_editor->destroy(); 531 533 532 $image_editor = new WP_Image_Editor_Imagick( $save_to_file ); 533 $image_editor->load(); 534 $image_editor->rotate( 180 ); 535 $image_editor->save( $save_to_file ); 534 $imagick_image_editor = new WP_Image_Editor_Imagick( $save_to_file ); 535 $imagick_image_editor->load(); 536 537 $imagick_image_editor->rotate( 180 ); 538 $imagick_image_editor->save( $save_to_file ); 536 539 537 540 $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0, 0 ), $pre_rotate_alpha ); 541 538 542 unlink( $save_to_file ); 539 543 } 540 544 541 545 /** 542 * Test WP_Image_Editor_Imagick handles extension-less images546 * Tests that WP_Image_Editor_Imagick handles extensionless images. 543 547 * 544 548 * @ticket 39195 545 549 */ 546 550 public function test_image_non_existent_extension() { 547 $image_editor = new WP_Image_Editor_Imagick( DIR_TESTDATA . '/images/test-image-no-extension' ); 548 $result = $image_editor->load(); 549 550 $this->assertTrue( $result ); 551 } 552 553 /** 554 * Test resetting Exif orientation data on rotate 551 $imagick_image_editor = new WP_Image_Editor_Imagick( DIR_TESTDATA . '/images/test-image-no-extension' ); 552 553 $loaded = $imagick_image_editor->load(); 554 555 $this->assertTrue( $loaded ); 556 } 557 558 /** 559 * Tests resetting Exif orientation data on rotate. 555 560 * 556 561 * @ticket 37140 … … 565 570 566 571 $temp_file = wp_tempnam( $file ); 567 $image = wp_get_image_editor( $file ); 572 573 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 574 $imagick_image_editor->load(); 568 575 569 576 // Test a value that would not lead back to 1, as WP is resetting the value to 1 manually. 570 $image->rotate( 90 ); 571 $ret = $image->save( $temp_file, 'image/jpeg' ); 572 573 $data = wp_read_image_metadata( $ret['path'] ); 577 $imagick_image_editor->rotate( 90 ); 578 $saved = $imagick_image_editor->save( $temp_file, 'image/jpeg' ); 579 580 $data = wp_read_image_metadata( $saved['path'] ); 581 582 // Remove both the generated file ending in .tmp and tmp.jpg due to wp_tempnam(). 583 unlink( $temp_file ); 584 unlink( $saved['path'] ); 574 585 575 586 // Make sure the image is no longer in The Upside Down Exif orientation. 576 587 $this->assertSame( 1, (int) $data['orientation'], 'Orientation Exif data was not updated after rotating image: ' . $file ); 577 578 // Remove both the generated file ending in .tmp and tmp.jpg due to wp_tempnam(). 579 unlink( $temp_file ); 580 unlink( $ret['path'] ); 581 } 582 583 /** 584 * Test that images can be loaded and written over streams 588 } 589 590 /** 591 * Tests that images can be loaded and written over streams. 585 592 */ 586 593 public function test_streams() { … … 595 602 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 596 603 597 $ ret= $imagick_image_editor->load();598 $this->assertNotWPError( $ ret);604 $loaded = $imagick_image_editor->load(); 605 $this->assertNotWPError( $loaded ); 599 606 600 607 $temp_file = 'wptest://Tests_Image_Editor_Imagick/write.jpg'; 601 608 602 $ret = $imagick_image_editor->save( $temp_file ); 603 $this->assertNotWPError( $ret ); 604 605 $this->assertSame( $temp_file, $ret['path'] ); 606 607 if ( $temp_file !== $ret['path'] ) { 608 unlink( $ret['path'] ); 609 $saved = $imagick_image_editor->save( $temp_file ); 610 611 if ( $temp_file !== $saved['path'] ) { 612 unlink( $saved['path'] ); 609 613 } 610 614 unlink( $temp_file ); 615 616 $this->assertNotWPError( $saved ); 617 $this->assertSame( $temp_file, $saved['path'] ); 611 618 } 612 619 … … 617 624 $file = realpath( DIR_TESTDATA ) . '/images/a2-small.jpg'; 618 625 $directory = realpath( DIR_TESTDATA ) . '/images/nonexistent-directory'; 619 $editor = new WP_Image_Editor_Imagick( $file ); 626 627 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 620 628 621 629 $this->assertFileDoesNotExist( $directory ); 622 630 623 $loaded = $ editor->load();631 $loaded = $imagick_image_editor->load(); 624 632 $this->assertNotWPError( $loaded ); 625 633 626 $resized = $ editor->resize( 100, 100, true );634 $resized = $imagick_image_editor->resize( 100, 100, true ); 627 635 $this->assertNotWPError( $resized ); 628 636 629 $saved = $editor->save( $directory . '/a2-small-cropped.jpg' ); 630 $this->assertNotWPError( $saved ); 637 $saved = $imagick_image_editor->save( $directory . '/a2-small-cropped.jpg' ); 631 638 632 639 unlink( $directory . '/a2-small-cropped.jpg' ); 633 640 rmdir( $directory ); 641 642 $this->assertNotWPError( $saved ); 634 643 } 635 644 }
Note: See TracChangeset
for help on using the changeset viewer.