Changeset 42343 for trunk/tests/phpunit/tests/post/attachments.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/attachments.php
r40531 r42343 19 19 20 20 $upload = wp_upload_bits( $filename, null, $contents ); 21 $this->assertTrue( empty( $upload['error']) );21 $this->assertTrue( empty( $upload['error'] ) ); 22 22 } 23 23 … … 25 25 26 26 // this image is smaller than the thumbnail size so it won't have one 27 $filename = ( DIR_TESTDATA .'/images/test-image.jpg' );28 $contents = file_get_contents( $filename);29 30 $upload = wp_upload_bits( basename($filename), null, $contents);31 $this->assertTrue( empty( $upload['error']) );32 33 $id = $this->_make_attachment( $upload);27 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); 28 $contents = file_get_contents( $filename ); 29 30 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 31 $this->assertTrue( empty( $upload['error'] ) ); 32 33 $id = $this->_make_attachment( $upload ); 34 34 35 35 // intermediate copies should not exist 36 $this->assertFalse( image_get_intermediate_size( $id, 'thumbnail') );37 $this->assertFalse( image_get_intermediate_size( $id, 'medium') );38 $this->assertFalse( image_get_intermediate_size( $id, 'medium_large') );36 $this->assertFalse( image_get_intermediate_size( $id, 'thumbnail' ) ); 37 $this->assertFalse( image_get_intermediate_size( $id, 'medium' ) ); 38 $this->assertFalse( image_get_intermediate_size( $id, 'medium_large' ) ); 39 39 40 40 // medium, medium_large, and full size will both point to the original 41 $downsize = image_downsize( $id, 'medium');42 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0]) );41 $downsize = image_downsize( $id, 'medium' ); 42 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); 43 43 $this->assertEquals( 50, $downsize[1] ); 44 44 $this->assertEquals( 50, $downsize[2] ); 45 45 46 $downsize = image_downsize( $id, 'medium_large');47 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0]) );46 $downsize = image_downsize( $id, 'medium_large' ); 47 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); 48 48 $this->assertEquals( 50, $downsize[1] ); 49 49 $this->assertEquals( 50, $downsize[2] ); 50 50 51 $downsize = image_downsize( $id, 'full');52 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0]) );51 $downsize = image_downsize( $id, 'full' ); 52 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); 53 53 $this->assertEquals( 50, $downsize[1] ); 54 54 $this->assertEquals( 50, $downsize[2] ); … … 57 57 58 58 function test_insert_image_thumb_only() { 59 if ( ! function_exists( 'imagejpeg' ) )59 if ( ! function_exists( 'imagejpeg' ) ) { 60 60 $this->fail( 'jpeg support unavailable' ); 61 } 61 62 62 63 update_option( 'medium_size_w', 0 ); 63 64 update_option( 'medium_size_h', 0 ); 64 65 65 $filename = ( DIR_TESTDATA .'/images/a2-small.jpg' );66 $contents = file_get_contents( $filename);67 68 $upload = wp_upload_bits( basename($filename), null, $contents);69 $this->assertTrue( empty( $upload['error']) );70 71 $id = $this->_make_attachment( $upload);66 $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); 67 $contents = file_get_contents( $filename ); 68 69 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 70 $this->assertTrue( empty( $upload['error'] ) ); 71 72 $id = $this->_make_attachment( $upload ); 72 73 73 74 // intermediate copies should exist: thumbnail only 74 $thumb = image_get_intermediate_size( $id, 'thumbnail');75 $thumb = image_get_intermediate_size( $id, 'thumbnail' ); 75 76 $this->assertEquals( 'a2-small-150x150.jpg', $thumb['file'] ); 76 77 77 78 $uploads = wp_upload_dir(); 78 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path']) );79 80 $this->assertFalse( image_get_intermediate_size( $id, 'medium') );81 $this->assertFalse( image_get_intermediate_size( $id, 'medium_large') );79 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) ); 80 81 $this->assertFalse( image_get_intermediate_size( $id, 'medium' ) ); 82 $this->assertFalse( image_get_intermediate_size( $id, 'medium_large' ) ); 82 83 83 84 // the thumb url should point to the thumbnail intermediate 84 $this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url( $id) );85 $this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url( $id ) ); 85 86 86 87 // image_downsize() should return the correct images and sizes 87 $downsize = image_downsize( $id, 'thumbnail');88 $this->assertEquals( 'a2-small-150x150.jpg', basename( $downsize[0]) );88 $downsize = image_downsize( $id, 'thumbnail' ); 89 $this->assertEquals( 'a2-small-150x150.jpg', basename( $downsize[0] ) ); 89 90 $this->assertEquals( 150, $downsize[1] ); 90 91 $this->assertEquals( 150, $downsize[2] ); 91 92 92 93 // medium, medium_large, and full will both point to the original 93 $downsize = image_downsize( $id, 'medium');94 $this->assertEquals( 'a2-small.jpg', basename( $downsize[0]) );94 $downsize = image_downsize( $id, 'medium' ); 95 $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) ); 95 96 $this->assertEquals( 400, $downsize[1] ); 96 97 $this->assertEquals( 300, $downsize[2] ); 97 98 98 $downsize = image_downsize( $id, 'medium_large');99 $this->assertEquals( 'a2-small.jpg', basename( $downsize[0]) );99 $downsize = image_downsize( $id, 'medium_large' ); 100 $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) ); 100 101 $this->assertEquals( 400, $downsize[1] ); 101 102 $this->assertEquals( 300, $downsize[2] ); 102 103 103 $downsize = image_downsize( $id, 'full');104 $this->assertEquals( 'a2-small.jpg', basename( $downsize[0]) );104 $downsize = image_downsize( $id, 'full' ); 105 $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) ); 105 106 $this->assertEquals( 400, $downsize[1] ); 106 107 $this->assertEquals( 300, $downsize[2] ); … … 109 110 110 111 function test_insert_image_medium_sizes() { 111 if ( ! function_exists( 'imagejpeg' ) )112 if ( ! function_exists( 'imagejpeg' ) ) { 112 113 $this->fail( 'jpeg support unavailable' ); 113 114 update_option('medium_size_w', 400); 115 update_option('medium_size_h', 0); 116 117 update_option('medium_large_size_w', 600); 118 update_option('medium_large_size_h', 0); 119 120 $filename = ( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG' ); 121 $contents = file_get_contents($filename); 122 123 $upload = wp_upload_bits(basename($filename), null, $contents); 124 $this->assertTrue( empty($upload['error']) ); 125 126 $id = $this->_make_attachment($upload); 114 } 115 116 update_option( 'medium_size_w', 400 ); 117 update_option( 'medium_size_h', 0 ); 118 119 update_option( 'medium_large_size_w', 600 ); 120 update_option( 'medium_large_size_h', 0 ); 121 122 $filename = ( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' ); 123 $contents = file_get_contents( $filename ); 124 125 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 126 $this->assertTrue( empty( $upload['error'] ) ); 127 128 $id = $this->_make_attachment( $upload ); 127 129 $uploads = wp_upload_dir(); 128 130 129 131 // intermediate copies should exist: thumbnail and medium 130 $thumb = image_get_intermediate_size( $id, 'thumbnail');132 $thumb = image_get_intermediate_size( $id, 'thumbnail' ); 131 133 $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] ); 132 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path']) );133 134 $medium = image_get_intermediate_size( $id, 'medium');134 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) ); 135 136 $medium = image_get_intermediate_size( $id, 'medium' ); 135 137 $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] ); 136 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path']) );137 138 $medium_large = image_get_intermediate_size( $id, 'medium_large');138 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path'] ) ); 139 140 $medium_large = image_get_intermediate_size( $id, 'medium_large' ); 139 141 $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] ); 140 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path']) );142 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) ); 141 143 142 144 // the thumb url should point to the thumbnail intermediate 143 $this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url( $id) );145 $this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url( $id ) ); 144 146 145 147 // image_downsize() should return the correct images and sizes 146 $downsize = image_downsize( $id, 'thumbnail');147 $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename( $downsize[0]) );148 $downsize = image_downsize( $id, 'thumbnail' ); 149 $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename( $downsize[0] ) ); 148 150 $this->assertEquals( 150, $downsize[1] ); 149 151 $this->assertEquals( 150, $downsize[2] ); 150 152 151 $downsize = image_downsize( $id, 'medium');152 $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', basename( $downsize[0]) );153 $downsize = image_downsize( $id, 'medium' ); 154 $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', basename( $downsize[0] ) ); 153 155 $this->assertEquals( 400, $downsize[1] ); 154 156 $this->assertEquals( 602, $downsize[2] ); 155 157 156 $downsize = image_downsize( $id, 'medium_large');157 $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', basename( $downsize[0]) );158 $downsize = image_downsize( $id, 'medium_large' ); 159 $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', basename( $downsize[0] ) ); 158 160 $this->assertEquals( 600, $downsize[1] ); 159 161 $this->assertEquals( 904, $downsize[2] ); 160 162 161 $downsize = image_downsize( $id, 'full');162 $this->assertEquals( '2007-06-17DSC_4173.jpg', basename( $downsize[0]) );163 $downsize = image_downsize( $id, 'full' ); 164 $this->assertEquals( '2007-06-17DSC_4173.jpg', basename( $downsize[0] ) ); 163 165 $this->assertEquals( 680, $downsize[1] ); 164 166 $this->assertEquals( 1024, $downsize[2] ); … … 167 169 168 170 function test_insert_image_delete() { 169 if ( ! function_exists( 'imagejpeg' ) )171 if ( ! function_exists( 'imagejpeg' ) ) { 170 172 $this->fail( 'jpeg support unavailable' ); 171 172 update_option('medium_size_w', 400); 173 update_option('medium_size_h', 0); 174 175 update_option('medium_large_size_w', 600); 176 update_option('medium_large_size_h', 0); 177 178 $filename = ( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG' ); 179 $contents = file_get_contents($filename); 180 181 $upload = wp_upload_bits(basename($filename), null, $contents); 182 $this->assertTrue( empty($upload['error']) ); 183 184 $id = $this->_make_attachment($upload); 173 } 174 175 update_option( 'medium_size_w', 400 ); 176 update_option( 'medium_size_h', 0 ); 177 178 update_option( 'medium_large_size_w', 600 ); 179 update_option( 'medium_large_size_h', 0 ); 180 181 $filename = ( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' ); 182 $contents = file_get_contents( $filename ); 183 184 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 185 $this->assertTrue( empty( $upload['error'] ) ); 186 187 $id = $this->_make_attachment( $upload ); 185 188 $uploads = wp_upload_dir(); 186 189 187 190 // check that the file and intermediates exist 188 $thumb = image_get_intermediate_size( $id, 'thumbnail');191 $thumb = image_get_intermediate_size( $id, 'thumbnail' ); 189 192 $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] ); 190 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path']) );191 192 $medium = image_get_intermediate_size( $id, 'medium');193 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) ); 194 195 $medium = image_get_intermediate_size( $id, 'medium' ); 193 196 $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] ); 194 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path']) );195 196 $medium_large = image_get_intermediate_size( $id, 'medium_large');197 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path'] ) ); 198 199 $medium_large = image_get_intermediate_size( $id, 'medium_large' ); 197 200 $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] ); 198 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path']) );199 200 $meta = wp_get_attachment_metadata($id);201 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) ); 202 203 $meta = wp_get_attachment_metadata( $id ); 201 204 $original = $meta['file']; 202 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $original) );205 $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $original ) ); 203 206 204 207 // now delete the attachment and make sure all files are gone 205 wp_delete_attachment( $id);206 207 $this->assertFalse( is_file( $thumb['path']) );208 $this->assertFalse( is_file( $medium['path']) );209 $this->assertFalse( is_file( $medium_large['path']) );210 $this->assertFalse( is_file( $original) );208 wp_delete_attachment( $id ); 209 210 $this->assertFalse( is_file( $thumb['path'] ) ); 211 $this->assertFalse( is_file( $medium['path'] ) ); 212 $this->assertFalse( is_file( $medium_large['path'] ) ); 213 $this->assertFalse( is_file( $original ) ); 211 214 } 212 215 213 216 /** 214 217 * GUID should never be empty 218 * 215 219 * @ticket 18310 216 220 * @ticket 21963 … … 218 222 function test_insert_image_without_guid() { 219 223 // this image is smaller than the thumbnail size so it won't have one 220 $filename = ( DIR_TESTDATA .'/images/test-image.jpg' );221 $contents = file_get_contents( $filename);222 223 $upload = wp_upload_bits( basename($filename), null, $contents);224 $this->assertTrue( empty( $upload['error']) );224 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); 225 $contents = file_get_contents( $filename ); 226 227 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 228 $this->assertTrue( empty( $upload['error'] ) ); 225 229 226 230 $upload['url'] = ''; 227 $id = $this->_make_attachment( $upload );231 $id = $this->_make_attachment( $upload ); 228 232 229 233 $guid = get_the_guid( $id ); … … 236 240 function test_update_attachment_fields() { 237 241 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); 238 $contents = file_get_contents( $filename);242 $contents = file_get_contents( $filename ); 239 243 240 244 $upload = wp_upload_bits( basename( $filename ), null, $contents ); … … 247 251 $post = get_post( $id, ARRAY_A ); 248 252 249 $post['post_title'] = 'title';253 $post['post_title'] = 'title'; 250 254 $post['post_excerpt'] = 'caption'; 251 255 $post['post_content'] = 'description'; … … 273 277 $this->assertEquals( $attachment->post_parent, 0 ); 274 278 275 $post_id = wp_insert_post( array( 'post_content' => rand_str(), 'post_title' => rand_str() ) ); 279 $post_id = wp_insert_post( 280 array( 281 'post_content' => rand_str(), 282 'post_title' => rand_str(), 283 ) 284 ); 276 285 277 286 // Assert that the attachment has a parent … … 350 359 351 360 // Ensure that server host matches the host of wp_upload_dir(). 352 $upload_dir = wp_upload_dir();361 $upload_dir = wp_upload_dir(); 353 362 $_SERVER['HTTP_HOST'] = parse_url( $upload_dir['baseurl'], PHP_URL_HOST ); 354 363 … … 378 387 379 388 // Ensure that server host matches the host of wp_upload_dir(). 380 $upload_dir = wp_upload_dir();389 $upload_dir = wp_upload_dir(); 381 390 $_SERVER['HTTP_HOST'] = parse_url( $upload_dir['baseurl'], PHP_URL_HOST ); 382 391 … … 388 397 389 398 /** 390 * @ticket 15928391 */399 * @ticket 15928 400 */ 392 401 public function test_wp_get_attachment_url_should_not_force_https_when_administering_over_https_but_siteurl_is_not_https() { 393 402 $siteurl = get_option( 'siteurl' ); … … 418 427 */ 419 428 public function test_wp_get_attachment_url_should_force_https_when_administering_over_https_and_siteurl_is_https() { 420 // Set https upload URL 429 // Set https upload URL 421 430 add_filter( 'upload_dir', '_upload_dir_https' ); 422 431 … … 446 455 $contents = file_get_contents( $filename ); 447 456 448 $upload = wp_upload_bits( basename( $filename ), null, $contents );457 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 449 458 $attachment_id = $this->_make_attachment( $upload ); 450 459 … … 464 473 $contents = file_get_contents( $filename ); 465 474 466 $upload = wp_upload_bits( basename( $filename ), null, $contents );475 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 467 476 $attachment_id = $this->_make_attachment( $upload ); 468 477
Note: See TracChangeset
for help on using the changeset viewer.