| 84 | |
| 85 | /** |
| 86 | * @ticket 17626 |
| 87 | */ |
| 88 | function test_get_intermediate_sizes_by_name() { |
| 89 | add_image_size( 'test-size', 330, 220, true ); |
| 90 | |
| 91 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 92 | $id = $this->_make_attachment( $file, 0 ); |
| 93 | |
| 94 | // look for a size by name |
| 95 | $image = image_get_intermediate_size( $id, 'test-size' ); |
| 96 | |
| 97 | // test for the expected string because the array will by definition |
| 98 | // return with the correct height and width attributes |
| 99 | $this->assertNotFalse( strpos( $image['file'], '330x220' ) ); |
| 100 | |
| 101 | // cleanup |
| 102 | remove_image_size('test-size'); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @ticket 17626 |
| 107 | */ |
| 108 | function test_get_intermediate_sizes_by_array_exact() { |
| 109 | // Only one dimention match shouldn't return false positive (see: 17626) |
| 110 | add_image_size( 'test-size', 330, 220, true ); |
| 111 | add_image_size( 'false-height', 330, 400, true); |
| 112 | add_image_size( 'false-width', 600, 220, true); |
| 113 | |
| 114 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 115 | $id = $this->_make_attachment( $file, 0 ); |
| 116 | |
| 117 | // look for a size by array that exists |
| 118 | // note: staying larger than 300px to miss default medium crop |
| 119 | $image = image_get_intermediate_size( $id, array(330,220) ); |
| 120 | |
| 121 | // test for the expected string because the array will by definition |
| 122 | // return with the correct height and width attributes |
| 123 | $this->assertNotFalse( strpos( $image['file'], '330x220' ) ); |
| 124 | |
| 125 | // cleanup |
| 126 | remove_image_size('test-size'); |
| 127 | remove_image_size('false-height'); |
| 128 | remove_image_size('false-width'); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * @ticket 17626 |
| 133 | */ |
| 134 | function test_get_intermediate_sizes_by_array_nearest() { |
| 135 | // If an exact size is not found, it should be returned |
| 136 | // If not, find nearest size that is larger (see: 17626) |
| 137 | add_image_size( 'test-size', 450, 300, true ); |
| 138 | add_image_size( 'false-height', 330, 100, true); |
| 139 | add_image_size( 'false-width', 150, 220, true); |
| 140 | |
| 141 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 142 | $id = $this->_make_attachment( $file, 0 ); |
| 143 | |
| 144 | // look for a size by array that doesn't exist |
| 145 | // note: staying larger than 300px to miss default medium crop |
| 146 | $image = image_get_intermediate_size( $id, array(330,220) ); |
| 147 | |
| 148 | // you have to test for the string because the image will by definition |
| 149 | // return with the correct height and width attributes |
| 150 | $this->assertNotFalse( strpos( $image['file'], '450x300' ) ); |
| 151 | |
| 152 | // cleanup |
| 153 | remove_image_size('test-size'); |
| 154 | remove_image_size('false-height'); |
| 155 | remove_image_size('false-width'); |
| 156 | |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @ticket 17626 |
| 161 | */ |
| 162 | function test_get_intermediate_sizes_by_array_nearest_false() { |
| 163 | // If an exact size is not found, it should be returned |
| 164 | // If not, find nearest size that is larger, otherwise return false (see: 17626) |
| 165 | add_image_size( 'false-height', 330, 100, true); |
| 166 | add_image_size( 'false-width', 150, 220, true); |
| 167 | |
| 168 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 169 | $id = $this->_make_attachment( $file, 0 ); |
| 170 | |
| 171 | // look for a size by array that doesn't exist |
| 172 | // note: staying larger than 300px to miss default medium crop |
| 173 | $image = image_get_intermediate_size( $id, array(330,220) ); |
| 174 | |
| 175 | // you have to test for the string because the image will by definition |
| 176 | // return with the correct height and width attributes |
| 177 | $this->assertFalse( $image ); |
| 178 | |
| 179 | // cleanup |
| 180 | remove_image_size('false-height'); |
| 181 | remove_image_size('false-width'); |
| 182 | |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * @ticket 17626 |
| 187 | */ |
| 188 | function test_get_intermediate_sizes_by_array_zero_height() { |
| 189 | // Generate random width |
| 190 | $random_w = rand(300,400); |
| 191 | |
| 192 | // Only one dimention match shouldn't return false positive (see: 17626) |
| 193 | add_image_size( 'test-size', $random_w, 0, false ); |
| 194 | add_image_size( 'false-height', $random_w, 100, true); |
| 195 | |
| 196 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 197 | $id = $this->_make_attachment( $file, 0 ); |
| 198 | |
| 199 | $original = wp_get_attachment_metadata( $id ); |
| 200 | $image_w = $random_w; |
| 201 | $image_h = round( ( $image_w / $original['width'] ) * $original['height'] ); |
| 202 | |
| 203 | // look for a size by array that exists |
| 204 | // note: staying larger than 300px to miss default medium crop |
| 205 | $image = image_get_intermediate_size( $id, array($random_w,0) ); |
| 206 | |
| 207 | // test for the expected string because the array will by definition |
| 208 | // return with the correct height and width attributes |
| 209 | $this->assertNotFalse( strpos( $image['file'], $image_w . 'x' . $image_h ) ); |
| 210 | |
| 211 | // cleanup |
| 212 | remove_image_size('test-size'); |
| 213 | remove_image_size('false-height'); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * @ticket 17626 |
| 218 | */ |
| 219 | function test_get_intermediate_sizes_by_array_zero_width() { |
| 220 | // Generate random height |
| 221 | $random_h = rand(200, 300); |
| 222 | |
| 223 | // Only one dimention match shouldn't return false positive (see: 17626) |
| 224 | add_image_size( 'test-size', 0, $random_h, false ); |
| 225 | add_image_size( 'false-height', 300, $random_h, true); |
| 226 | |
| 227 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 228 | $id = $this->_make_attachment( $file, 0 ); |
| 229 | |
| 230 | $original = wp_get_attachment_metadata( $id ); |
| 231 | $image_h = $random_h; |
| 232 | $image_w = round( ( $image_h / $original['height'] ) * $original['width'] ); |
| 233 | |
| 234 | // look for a size by array that exists |
| 235 | // note: staying larger than 300px to miss default medium crop |
| 236 | $image = image_get_intermediate_size( $id, array(0,$random_h) ); |
| 237 | |
| 238 | // test for the expected string because the array will by definition |
| 239 | // return with the correct height and width attributes |
| 240 | $this->assertNotFalse( strpos( $image['file'], $image_w . 'x' . $image_h ) ); |
| 241 | |
| 242 | // cleanup |
| 243 | remove_image_size('test-size'); |
| 244 | remove_image_size('false-height'); |
| 245 | } |