Changeset 54401
- Timestamp:
- 10/07/2022 12:40:07 AM (22 months ago)
- Location:
- trunk/tests/phpunit/tests/image
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/editorGd.php
r54226 r54401 53 53 54 54 /** 55 * Test resizing an image, not using crop55 * Test 56 56 * 57 57 * @requires function imagejpeg … … 75 75 76 76 /** 77 * Test multi_resize with single image resize and no crop77 * Test 78 78 * 79 79 * @requires function imagejpeg … … 117 117 118 118 /** 119 * Ensure multi_resize doesn't create an image when119 * t create an image when 120 120 * both height and weight are missing, null, or 0. 121 121 * … … 186 186 187 187 /** 188 * Test multi_resize with multiple sizes188 * Test 189 189 * 190 190 * @ticket 26823 … … 199 199 $sizes_array = array( 200 200 201 /* *201 /* 202 202 * #0 - 10x10 resize, no cropping. 203 203 * By aspect, should be 10x6 output. … … 209 209 ), 210 210 211 /* *211 /* 212 212 * #1 - 75x50 resize, with cropping. 213 213 * Output dimensions should be 75x50 … … 219 219 ), 220 220 221 /* *221 /* 222 222 * #2 - 20 pixel max height, no cropping. 223 223 * By aspect, should be 30x20 output. … … 229 229 ), 230 230 231 /* *231 /* 232 232 * #3 - 45 pixel max height, with cropping. 233 233 * By aspect, should be 45x400 output. … … 239 239 ), 240 240 241 /* *241 /* 242 242 * #4 - 50 pixel max width, no cropping. 243 243 * By aspect, should be 50x33 output. … … 247 247 ), 248 248 249 /* *249 /* 250 250 * #5 - 55 pixel max width, no cropping, null height 251 251 * By aspect, should be 55x36 output. … … 256 256 ), 257 257 258 /* *258 /* 259 259 * #6 - 55 pixel max height, no cropping, no width specified. 260 260 * By aspect, should be 82x55 output. … … 264 264 ), 265 265 266 /* *266 /* 267 267 * #7 - 60 pixel max height, no cropping, null width. 268 268 * By aspect, should be 90x60 output. … … 273 273 ), 274 274 275 /* *275 /* 276 276 * #8 - 70 pixel max height, no cropping, negative width. 277 277 * By aspect, should be 105x70 output. … … 282 282 ), 283 283 284 /* *284 /* 285 285 * #9 - 200 pixel max width, no cropping, negative height. 286 286 * By aspect, should be 200x133 output. … … 403 403 404 404 /** 405 * Test resizing an image with cropping405 * Test 406 406 */ 407 407 public function test_resize_and_crop() { … … 423 423 424 424 /** 425 * Test cropping an image.425 * Test cropping an image. 426 426 * 427 427 * @ticket 51937 … … 480 480 481 481 /** 482 * Test should returnWP_Error when dimensions are not integer or are <= 0.482 * Test WP_Error when dimensions are not integer or are <= 0. 483 483 * 484 484 * @ticket 51937 … … 546 546 547 547 /** 548 * Test rotating an image 180 deg548 * Test 549 549 */ 550 550 public function test_rotate() { … … 565 565 566 566 /** 567 * Test flipping an image567 * Test 568 568 */ 569 569 public function test_flip() { … … 584 584 585 585 /** 586 * Test the image created with WP_Image_Editor_GD preserves alpha when resizing 586 * Tests that an image created with WP_Image_Editor_GD preserves alpha with no resizing. 587 * 588 * @ticket 23039 589 */ 590 public function test_image_preserves_alpha() { 591 if ( ! ( imagetypes() & IMG_PNG ) ) { 592 $this->fail( 'This test requires PHP to be compiled with PNG support.' ); 593 } 594 595 $file = DIR_TESTDATA . '/images/transparent.png'; 596 597 $gd_image_editor = new WP_Image_Editor_GD( $file ); 598 $gd_image_editor->load(); 599 600 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 601 602 $gd_image_editor->save( $save_to_file ); 603 604 $this->assertImageAlphaAtPointGD( $save_to_file, array( 0, 0 ), 127 ); 605 606 unlink( $save_to_file ); 607 } 608 609 /** 610 * Tests that an image created with WP_Image_Editor_GD preserves alpha when resizing. 587 611 * 588 612 * @ticket 23039 … … 595 619 $file = DIR_TESTDATA . '/images/transparent.png'; 596 620 597 $editor = wp_get_image_editor( $file ); 598 599 $this->assertNotWPError( $editor ); 600 601 $editor->load(); 602 $editor->resize( 5, 5 ); 621 $gd_image_editor = new WP_Image_Editor_GD( $file ); 622 $gd_image_editor->load(); 623 624 $gd_image_editor->resize( 5, 5 ); 603 625 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 604 626 605 $editor->save( $save_to_file ); 606 607 $this->assertImageAlphaAtPointGD( $save_to_file, array( 0, 0 ), 127 ); 608 609 unlink( $save_to_file ); 610 } 611 612 /** 613 * Test the image created with WP_Image_Editor_GD preserves alpha with no resizing etc 614 * 615 * @ticket 23039 616 */ 617 public function test_image_preserves_alpha() { 618 if ( ! ( imagetypes() & IMG_PNG ) ) { 619 $this->fail( 'This test requires PHP to be compiled with PNG support.' ); 620 } 621 622 $file = DIR_TESTDATA . '/images/transparent.png'; 623 624 $editor = wp_get_image_editor( $file ); 625 626 $this->assertNotWPError( $editor ); 627 628 $editor->load(); 629 630 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 631 632 $editor->save( $save_to_file ); 627 $gd_image_editor->save( $save_to_file ); 633 628 634 629 $this->assertImageAlphaAtPointGD( $save_to_file, array( 0, 0 ), 127 ); … … 651 646 $expected = imagecolorsforindex( $image, $rgb ); 652 647 653 $editor = new WP_Image_Editor_GD( $file ); 654 $editor->load(); 655 $editor->rotate( 180 ); 656 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 657 658 $editor->save( $save_to_file ); 659 660 $this->assertImageAlphaAtPointGD( $save_to_file, array( 0, 0 ), $expected['alpha'] ); 661 unlink( $save_to_file ); 662 663 } 664 665 /** 666 * Test WP_Image_Editor_GD handles extension-less images 648 $gd_image_editor = new WP_Image_Editor_GD( $file ); 649 $gd_image_editor->load(); 650 651 $gd_image_editor->rotate( 180 ); 652 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 653 654 $gd_image_editor->save( $save_to_file ); 655 656 $this->assertImageAlphaAtPointGD( $save_to_file, array( 0, 0 ), $expected['alpha'] ); 657 658 unlink( $save_to_file ); 659 } 660 661 /** 662 * Tests that WP_Image_Editor_GD handles extensionless images. 667 663 * 668 664 * @ticket 39195 669 665 */ 670 666 public function test_image_non_existent_extension() { 671 $image_editor = new WP_Image_Editor_GD( DIR_TESTDATA . '/images/test-image-no-extension' ); 672 $result = $image_editor->load(); 673 674 $this->assertTrue( $result ); 667 $gd_image_editor = new WP_Image_Editor_GD( DIR_TESTDATA . '/images/test-image-no-extension' ); 668 669 $loaded = $gd_image_editor->load(); 670 671 $this->assertTrue( $loaded ); 675 672 } 676 673 } -
trunk/tests/phpunit/tests/image/editorImagick.php
r54226 r54401 36 36 37 37 /** 38 * Checksupport for ImageMagick compatible mime types.38 * 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 * Test 50 50 */ 51 51 public function test_resize() { … … 67 67 68 68 /** 69 * Test multi_resize with single image resize and no crop69 * Test 70 70 */ 71 71 public function test_single_multi_resize() { … … 107 107 108 108 /** 109 * Ensure multi_resize doesn't create an image when109 * t 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 * Test 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 * Test 395 395 */ 396 396 public function test_resize_and_crop() { … … 412 412 413 413 /** 414 * Test cropping an image414 * Test 415 415 */ 416 416 public function test_crop() { … … 432 432 433 433 /** 434 * Test rotating an image 180 deg434 * Test 435 435 */ 436 436 public function test_rotate() { … … 451 451 452 452 /** 453 * Test flipping an image453 * Test 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 * Test 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 $editor = new WP_Image_Editor_Imagick( $file ); 480 $editor->load(); 481 482 482 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 483 483 484 $ editor->save( $save_to_file );484 $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 * Test 497 497 * 498 498 * @ticket 24871 499 499 */ 500 public function test_image_preserves_alpha () {500 public function test_image_preserves_alpha() { 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 $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 * Test 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 $ = $imagick_image_editor->load(); 605 $this->assertNotWPError( $ ); 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 617 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 = $editor->load(); 624 632 $this->assertNotWPError( $loaded ); 625 633 626 $resized = $ editor->resize( 100, 100, true );634 $resized = $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 634 643 } 635 644 }
Note: See TracChangeset
for help on using the changeset viewer.