Changeset 47122 for trunk/tests/phpunit/tests/image/dimensions.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/dimensions.php
r46586 r47122 8 8 class Tests_Image_Dimensions extends WP_UnitTestCase { 9 9 function test_400x400_no_crop() { 10 // landscape: resize 640x480 to fit 400x400: 400x30010 // Landscape: resize 640x480 to fit 400x400: 400x300. 11 11 $out = image_resize_dimensions( 640, 480, 400, 400, false ); 12 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 12 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 13 13 $this->assertEquals( array( 0, 0, 0, 0, 400, 300, 640, 480 ), $out ); 14 14 15 // portrait: resize 480x640 to fit 400x400: 300x40015 // Portrait: resize 480x640 to fit 400x400: 300x400. 16 16 $out = image_resize_dimensions( 480, 640, 400, 400, false ); 17 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 17 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 18 18 $this->assertEquals( array( 0, 0, 0, 0, 300, 400, 480, 640 ), $out ); 19 19 } 20 20 21 21 function test_400x0_no_crop() { 22 // landscape: resize 640x480 to fit 400w: 400x30022 // Landscape: resize 640x480 to fit 400w: 400x300. 23 23 $out = image_resize_dimensions( 640, 480, 400, 0, false ); 24 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 24 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 25 25 $this->assertEquals( array( 0, 0, 0, 0, 400, 300, 640, 480 ), $out ); 26 26 27 // portrait: resize 480x640 to fit 400w: 400x53327 // Portrait: resize 480x640 to fit 400w: 400x533. 28 28 $out = image_resize_dimensions( 480, 640, 400, 0, false ); 29 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 29 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 30 30 $this->assertEquals( array( 0, 0, 0, 0, 400, 533, 480, 640 ), $out ); 31 31 } 32 32 33 33 function test_0x400_no_crop() { 34 // landscape: resize 640x480 to fit 400h: 533x40034 // Landscape: resize 640x480 to fit 400h: 533x400. 35 35 $out = image_resize_dimensions( 640, 480, 0, 400, false ); 36 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 36 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 37 37 $this->assertEquals( array( 0, 0, 0, 0, 533, 400, 640, 480 ), $out ); 38 38 39 // portrait: resize 480x640 to fit 400h: 300x40039 // Portrait: resize 480x640 to fit 400h: 300x400. 40 40 $out = image_resize_dimensions( 480, 640, 0, 400, false ); 41 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 41 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 42 42 $this->assertEquals( array( 0, 0, 0, 0, 300, 400, 480, 640 ), $out ); 43 43 } 44 44 45 45 function test_800x800_no_crop() { 46 // landscape: resize 640x480 to fit 800x80046 // Landscape: resize 640x480 to fit 800x800. 47 47 $out = image_resize_dimensions( 640, 480, 800, 800, false ); 48 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 48 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 49 49 $this->assertEquals( false, $out ); 50 50 51 // portrait: resize 480x640 to fit 800x80051 // Portrait: resize 480x640 to fit 800x800. 52 52 $out = image_resize_dimensions( 480, 640, 800, 800, false ); 53 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 53 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 54 54 $this->assertEquals( false, $out ); 55 55 } 56 56 57 57 function test_800x0_no_crop() { 58 // landscape: resize 640x480 to fit 800w58 // Landscape: resize 640x480 to fit 800w. 59 59 $out = image_resize_dimensions( 640, 480, 800, 0, false ); 60 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 60 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 61 61 $this->assertEquals( false, $out ); 62 62 63 // portrait: resize 480x640 to fit 800w63 // Portrait: resize 480x640 to fit 800w. 64 64 $out = image_resize_dimensions( 480, 640, 800, 0, false ); 65 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 65 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 66 66 $this->assertEquals( false, $out ); 67 67 } 68 68 69 69 function test_0x800_no_crop() { 70 // landscape: resize 640x480 to fit 800h70 // Landscape: resize 640x480 to fit 800h. 71 71 $out = image_resize_dimensions( 640, 480, 0, 800, false ); 72 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 72 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 73 73 $this->assertEquals( false, $out ); 74 74 75 // portrait: resize 480x640 to fit 800h75 // Portrait: resize 480x640 to fit 800h. 76 76 $out = image_resize_dimensions( 480, 640, 0, 800, false ); 77 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 77 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 78 78 $this->assertEquals( false, $out ); 79 79 } 80 80 81 // cropped versions81 // Cropped versions. 82 82 83 83 function test_400x400_crop() { 84 // landscape: crop 640x480 to fit 400x400: 400x400 taken from a 480x480 crop at (80. 0)84 // Landscape: crop 640x480 to fit 400x400: 400x400 taken from a 480x480 crop at (80. 0). 85 85 $out = image_resize_dimensions( 640, 480, 400, 400, true ); 86 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 86 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 87 87 $this->assertEquals( array( 0, 0, 80, 0, 400, 400, 480, 480 ), $out ); 88 88 89 // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80)89 // Portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80). 90 90 $out = image_resize_dimensions( 480, 640, 400, 400, true ); 91 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 91 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 92 92 $this->assertEquals( array( 0, 0, 0, 80, 400, 400, 480, 480 ), $out ); 93 93 } 94 94 95 95 function test_400x0_crop() { 96 // landscape: resize 640x480 to fit 400w: 400x30096 // Landscape: resize 640x480 to fit 400w: 400x300. 97 97 $out = image_resize_dimensions( 640, 480, 400, 0, true ); 98 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 98 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 99 99 $this->assertEquals( array( 0, 0, 0, 0, 400, 300, 640, 480 ), $out ); 100 100 101 // portrait: resize 480x640 to fit 400w: 400x533101 // Portrait: resize 480x640 to fit 400w: 400x533. 102 102 $out = image_resize_dimensions( 480, 640, 400, 0, true ); 103 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 103 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 104 104 $this->assertEquals( array( 0, 0, 0, 0, 400, 533, 480, 640 ), $out ); 105 105 } 106 106 107 107 function test_0x400_crop() { 108 // landscape: resize 640x480 to fit 400h: 533x400108 // Landscape: resize 640x480 to fit 400h: 533x400. 109 109 $out = image_resize_dimensions( 640, 480, 0, 400, true ); 110 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 110 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 111 111 $this->assertEquals( array( 0, 0, 0, 0, 533, 400, 640, 480 ), $out ); 112 112 113 // portrait: resize 480x640 to fit 400h: 300x400113 // Portrait: resize 480x640 to fit 400h: 300x400. 114 114 $out = image_resize_dimensions( 480, 640, 0, 400, true ); 115 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 115 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 116 116 $this->assertEquals( array( 0, 0, 0, 0, 300, 400, 480, 640 ), $out ); 117 117 } 118 118 119 119 function test_400x500_crop() { 120 // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop at (80. 0)120 // Landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop at (80. 0). 121 121 $out = image_resize_dimensions( 640, 480, 400, 500, true ); 122 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 122 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 123 123 $this->assertEquals( array( 0, 0, 120, 0, 400, 480, 400, 480 ), $out ); 124 124 125 // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80)125 // Portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80). 126 126 $out = image_resize_dimensions( 480, 640, 400, 500, true ); 127 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 127 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 128 128 $this->assertEquals( array( 0, 0, 0, 20, 400, 500, 480, 600 ), $out ); 129 129 } 130 130 131 131 function test_640x480() { 132 // crop 640x480 to fit 640x480 (no change)132 // Crop 640x480 to fit 640x480 (no change). 133 133 $out = image_resize_dimensions( 640, 480, 640, 480, true ); 134 134 $this->assertFalse( $out ); 135 135 136 // resize 640x480 to fit 640x480 (no change)136 // Resize 640x480 to fit 640x480 (no change). 137 137 $out = image_resize_dimensions( 640, 480, 640, 480, false ); 138 138 $this->assertFalse( $out ); … … 141 141 add_filter( 'wp_image_resize_identical_dimensions', '__return_true' ); 142 142 143 // crop 640x480 to fit 640x480 (no change)143 // Crop 640x480 to fit 640x480 (no change). 144 144 $out = image_resize_dimensions( 640, 480, 640, 480, true ); 145 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 145 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 146 146 $this->assertEquals( array( 0, 0, 0, 0, 640, 480, 640, 480 ), $out ); 147 147 148 // resize 640x480 to fit 640x480 (no change)148 // Resize 640x480 to fit 640x480 (no change). 149 149 $out = image_resize_dimensions( 640, 480, 640, 480, false ); 150 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 150 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 151 151 $this->assertEquals( array( 0, 0, 0, 0, 640, 480, 640, 480 ), $out ); 152 152 … … 158 158 */ 159 159 function test_crop_anchors() { 160 // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop161 // src_x = 0 (left), src_y = 0 (top) 160 // Landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop. 161 // src_x = 0 (left), src_y = 0 (top). 162 162 $out = image_resize_dimensions( 640, 480, 400, 500, array( 'left', 'top' ) ); 163 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 163 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 164 164 $this->assertEquals( array( 0, 0, 0, 0, 400, 480, 400, 480 ), $out ); 165 165 166 // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop167 // src_x = 0 (left), src_y = 0 (top) 166 // Portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop. 167 // src_x = 0 (left), src_y = 0 (top). 168 168 $out = image_resize_dimensions( 480, 640, 400, 500, array( 'left', 'top' ) ); 169 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 169 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 170 170 $this->assertEquals( array( 0, 0, 0, 0, 400, 500, 480, 600 ), $out ); 171 171 172 // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop173 // src_x = 240 (left), src_y = 0 (due to landscape crop) 172 // Landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop. 173 // src_x = 240 (left), src_y = 0 (due to landscape crop). 174 174 $out = image_resize_dimensions( 640, 480, 400, 500, array( 'right', 'bottom' ) ); 175 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 175 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 176 176 $this->assertEquals( array( 0, 0, 240, 0, 400, 480, 400, 480 ), $out ); 177 177 178 // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop179 // src_x = 0 (due to portrait crop), src_y = 40 (bottom) 178 // Portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop. 179 // src_x = 0 (due to portrait crop), src_y = 40 (bottom). 180 180 $out = image_resize_dimensions( 480, 640, 400, 500, array( 'right', 'bottom' ) ); 181 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h 181 // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. 182 182 $this->assertEquals( array( 0, 0, 0, 40, 400, 500, 480, 600 ), $out ); 183 183 }
Note: See TracChangeset
for help on using the changeset viewer.