dimensions.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * @group image
  4. * @group media
  5. * @group upload
  6. */
  7. class Tests_Image_Dimensions extends WP_UnitTestCase {
  8. function test_400x400_no_crop() {
  9. // landscape: resize 640x480 to fit 400x400: 400x300
  10. $out = image_resize_dimensions(640, 480, 400, 400, false);
  11. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  12. $this->assertEquals( array(0, 0, 0, 0, 400, 300, 640, 480), $out );
  13. // portrait: resize 480x640 to fit 400x400: 300x400
  14. $out = image_resize_dimensions(480, 640, 400, 400, false);
  15. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  16. $this->assertEquals( array(0, 0, 0, 0, 300, 400, 480, 640), $out );
  17. }
  18. function test_400x0_no_crop() {
  19. // landscape: resize 640x480 to fit 400w: 400x300
  20. $out = image_resize_dimensions(640, 480, 400, 0, false);
  21. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  22. $this->assertEquals( array(0, 0, 0, 0, 400, 300, 640, 480), $out );
  23. // portrait: resize 480x640 to fit 400w: 400x533
  24. $out = image_resize_dimensions(480, 640, 400, 0, false);
  25. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  26. $this->assertEquals( array(0, 0, 0, 0, 400, 533, 480, 640), $out );
  27. }
  28. function test_0x400_no_crop() {
  29. // landscape: resize 640x480 to fit 400h: 533x400
  30. $out = image_resize_dimensions(640, 480, 0, 400, false);
  31. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  32. $this->assertEquals( array(0, 0, 0, 0, 533, 400, 640, 480), $out );
  33. // portrait: resize 480x640 to fit 400h: 300x400
  34. $out = image_resize_dimensions(480, 640, 0, 400, false);
  35. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  36. $this->assertEquals( array(0, 0, 0, 0, 300, 400, 480, 640), $out );
  37. }
  38. function test_800x800_no_crop() {
  39. // landscape: resize 640x480 to fit 800x800
  40. $out = image_resize_dimensions(640, 480, 800, 800, false);
  41. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  42. $this->assertEquals( false, $out );
  43. // portrait: resize 480x640 to fit 800x800
  44. $out = image_resize_dimensions(480, 640, 800, 800, false);
  45. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  46. $this->assertEquals( false, $out );
  47. }
  48. function test_800x0_no_crop() {
  49. // landscape: resize 640x480 to fit 800w
  50. $out = image_resize_dimensions(640, 480, 800, 0, false);
  51. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  52. $this->assertEquals( false, $out );
  53. // portrait: resize 480x640 to fit 800w
  54. $out = image_resize_dimensions(480, 640, 800, 0, false);
  55. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  56. $this->assertEquals( false, $out );
  57. }
  58. function test_0x800_no_crop() {
  59. // landscape: resize 640x480 to fit 800h
  60. $out = image_resize_dimensions(640, 480, 0, 800, false);
  61. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  62. $this->assertEquals( false, $out );
  63. // portrait: resize 480x640 to fit 800h
  64. $out = image_resize_dimensions(480, 640, 0, 800, false);
  65. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  66. $this->assertEquals( false, $out );
  67. }
  68. // cropped versions
  69. function test_400x400_crop() {
  70. // landscape: crop 640x480 to fit 400x400: 400x400 taken from a 480x480 crop at (80. 0)
  71. $out = image_resize_dimensions(640, 480, 400, 400, true);
  72. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  73. $this->assertEquals( array(0, 0, 80, 0, 400, 400, 480, 480), $out );
  74. // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80)
  75. $out = image_resize_dimensions(480, 640, 400, 400, true);
  76. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  77. $this->assertEquals( array(0, 0, 0, 80, 400, 400, 480, 480), $out );
  78. }
  79. function test_400x0_crop() {
  80. // landscape: resize 640x480 to fit 400w: 400x300
  81. $out = image_resize_dimensions(640, 480, 400, 0, true);
  82. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  83. $this->assertEquals( array(0, 0, 0, 0, 400, 300, 640, 480), $out );
  84. // portrait: resize 480x640 to fit 400w: 400x533
  85. $out = image_resize_dimensions(480, 640, 400, 0, true);
  86. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  87. $this->assertEquals( array(0, 0, 0, 0, 400, 533, 480, 640), $out );
  88. }
  89. function test_0x400_crop() {
  90. // landscape: resize 640x480 to fit 400h: 533x400
  91. $out = image_resize_dimensions(640, 480, 0, 400, true);
  92. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  93. $this->assertEquals( array(0, 0, 0, 0, 533, 400, 640, 480), $out );
  94. // portrait: resize 480x640 to fit 400h: 300x400
  95. $out = image_resize_dimensions(480, 640, 0, 400, true);
  96. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  97. $this->assertEquals( array(0, 0, 0, 0, 300, 400, 480, 640), $out );
  98. }
  99. function test_400x500_crop() {
  100. // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop at (80. 0)
  101. $out = image_resize_dimensions(640, 480, 400, 500, true);
  102. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  103. $this->assertEquals( array(0, 0, 120, 0, 400, 480, 400, 480), $out );
  104. // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80)
  105. $out = image_resize_dimensions(480, 640, 400, 500, true);
  106. // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
  107. $this->assertEquals( array(0, 0, 0, 20, 400, 500, 480, 600), $out );
  108. }
  109. }