diff --git tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
index 7288af6d63..113f67616d 100644
|
|
|
class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { |
| 33 | 33 | return wp_insert_attachment( $r, $r['file'], $r['post_parent'] ); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | | function create_upload_object( $file, $parent = 0 ) { |
| | 36 | /** |
| | 37 | * Upload a file and create an associated attachment post. |
| | 38 | * |
| | 39 | * @since 4.4.0 |
| | 40 | * |
| | 41 | * @param string $file Path of the file to upload and associate to the attachment. |
| | 42 | * @param int $parent Optional. Attachment parent post id. |
| | 43 | * |
| | 44 | * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. |
| | 45 | */ |
| | 46 | public function create_upload_object( $file, $parent = 0 ) { |
| 37 | 47 | $contents = file_get_contents( $file ); |
| 38 | 48 | $upload = wp_upload_bits( basename( $file ), null, $contents ); |
| 39 | 49 | |
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
index fee06e0df9..4272a02d39 100644
|
|
|
class WP_UnitTestCase extends PHPUnit_Framework_TestCase { |
| 1032 | 1032 | * Creates an attachment post from an uploaded file. |
| 1033 | 1033 | * |
| 1034 | 1034 | * @since 4.4.0 |
| | 1035 | * @deprecated 5.0.0 Use WP_UnitTest_Factory_For_Attachment::create_upload_object() instead. |
| 1035 | 1036 | * |
| 1036 | 1037 | * @param array $upload Array of information about the uploaded file, provided by wp_upload_bits(). |
| 1037 | 1038 | * @param int $parent_post_id Optional. Parent post ID. |
| … |
… |
class WP_UnitTestCase extends PHPUnit_Framework_TestCase { |
| 1039 | 1040 | * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. |
| 1040 | 1041 | */ |
| 1041 | 1042 | function _make_attachment( $upload, $parent_post_id = 0 ) { |
| 1042 | | $type = ''; |
| 1043 | | if ( ! empty( $upload['type'] ) ) { |
| 1044 | | $type = $upload['type']; |
| 1045 | | } else { |
| 1046 | | $mime = wp_check_filetype( $upload['file'] ); |
| 1047 | | if ( $mime ) { |
| 1048 | | $type = $mime['type']; |
| 1049 | | } |
| 1050 | | } |
| 1051 | | |
| 1052 | | $attachment = array( |
| 1053 | | 'post_title' => basename( $upload['file'] ), |
| 1054 | | 'post_content' => '', |
| 1055 | | 'post_type' => 'attachment', |
| 1056 | | 'post_parent' => $parent_post_id, |
| 1057 | | 'post_mime_type' => $type, |
| 1058 | | 'guid' => $upload['url'], |
| 1059 | | ); |
| | 1043 | trigger_error( __METHOD__ . ' is deprecated since version 5.0.0. Use WP_UnitTest_Factory_For_Attachment::create_upload_object() instead' ); |
| 1060 | 1044 | |
| 1061 | | $id = wp_insert_attachment( $attachment, $upload['file'], $parent_post_id ); |
| 1062 | | wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); |
| 1063 | | return $id; |
| | 1045 | return self::factory()->attachment->create_upload_object( $upload['file'], $parent_post_id ); |
| 1064 | 1046 | } |
| 1065 | 1047 | |
| 1066 | 1048 | /** |
diff --git tests/phpunit/tests/ajax/Attachments.php tests/phpunit/tests/ajax/Attachments.php
index cf11ddc5a0..31012f687d 100644
|
|
|
class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { |
| 26 | 26 | wp_set_current_user( $user_id ); |
| 27 | 27 | $_POST = array_merge( $_POST, $post ); |
| 28 | 28 | |
| 29 | | $filename = DIR_TESTDATA . '/images/canola.jpg'; |
| 30 | | $contents = file_get_contents( $filename ); |
| 31 | | |
| 32 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 33 | | $attachment = $this->_make_attachment( $upload ); |
| | 29 | $attachment = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' ); |
| 34 | 30 | |
| 35 | 31 | // Set up a default request |
| 36 | 32 | $_POST['nonce'] = wp_create_nonce( 'media-send-to-editor' ); |
| … |
… |
class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { |
| 77 | 73 | wp_set_current_user( $user_id ); |
| 78 | 74 | $_POST = array_merge( $_POST, $post ); |
| 79 | 75 | |
| 80 | | $filename = DIR_TESTDATA . '/formatting/entities.txt'; |
| 81 | | $contents = file_get_contents( $filename ); |
| 82 | | |
| 83 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 84 | | $attachment = $this->_make_attachment( $upload ); |
| | 76 | $attachment = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/formatting/entities.txt' ); |
| 85 | 77 | |
| 86 | 78 | // Set up a default request |
| 87 | 79 | $_POST['nonce'] = wp_create_nonce( 'media-send-to-editor' ); |
diff --git tests/phpunit/tests/ajax/MediaEdit.php tests/phpunit/tests/ajax/MediaEdit.php
index a55e3829a8..892893be1b 100644
|
|
|
class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { |
| 29 | 29 | public function testCropImageThumbnail() { |
| 30 | 30 | include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); |
| 31 | 31 | |
| 32 | | $filename = DIR_TESTDATA . '/images/canola.jpg'; |
| 33 | | $contents = file_get_contents( $filename ); |
| 34 | | |
| 35 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 36 | | $id = $this->_make_attachment( $upload ); |
| | 32 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' ); |
| 37 | 33 | |
| 38 | 34 | $_REQUEST['action'] = 'image-editor'; |
| 39 | 35 | $_REQUEST['context'] = 'edit-attachment'; |
| … |
… |
class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { |
| 60 | 56 | |
| 61 | 57 | include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); |
| 62 | 58 | |
| 63 | | $filename = DIR_TESTDATA . '/images/canola.jpg'; |
| 64 | | $contents = file_get_contents( $filename ); |
| 65 | | |
| 66 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 67 | | $id = $this->_make_attachment( $upload ); |
| | 59 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' ); |
| 68 | 60 | |
| 69 | 61 | $_REQUEST['action'] = 'image-editor'; |
| 70 | 62 | $_REQUEST['context'] = 'edit-attachment'; |
diff --git tests/phpunit/tests/general/template.php tests/phpunit/tests/general/template.php
index 05ef9777d8..c0423afe4f 100644
|
|
|
class Tests_General_Template extends WP_UnitTestCase { |
| 228 | 228 | * @since 4.3.0 |
| 229 | 229 | */ |
| 230 | 230 | function _insert_attachment() { |
| 231 | | $filename = DIR_TESTDATA . '/images/test-image.jpg'; |
| 232 | | $contents = file_get_contents( $filename ); |
| 233 | | |
| 234 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 235 | | $this->site_icon_url = $upload['url']; |
| 236 | | |
| 237 | | // Save the data |
| 238 | | $this->site_icon_id = $this->_make_attachment( $upload ); |
| | 231 | $this->site_icon_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| | 232 | $this->site_icon_url = wp_get_attachment_url( $this->site_icon_id ); |
| 239 | 233 | return $this->site_icon_id; |
| 240 | 234 | } |
| 241 | 235 | |
| … |
… |
class Tests_General_Template extends WP_UnitTestCase { |
| 404 | 398 | * @since 4.5.0 |
| 405 | 399 | */ |
| 406 | 400 | function _insert_custom_logo() { |
| 407 | | $filename = DIR_TESTDATA . '/images/test-image.jpg'; |
| 408 | | $contents = file_get_contents( $filename ); |
| 409 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 410 | | |
| 411 | | // Save the data. |
| 412 | | $this->custom_logo_url = $upload['url']; |
| 413 | | $this->custom_logo_id = $this->_make_attachment( $upload ); |
| | 401 | $this->custom_logo_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| | 402 | $this->custom_logo_url = wp_get_attachment_url( $this->custom_logo_id ); |
| 414 | 403 | return $this->custom_logo_id; |
| 415 | 404 | } |
| 416 | 405 | |
diff --git tests/phpunit/tests/image/intermediateSize.php tests/phpunit/tests/image/intermediateSize.php
index 95ee173edd..99b94bea21 100644
|
|
|
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 15 | 15 | parent::tearDown(); |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | | public function _make_attachment( $file, $parent_post_id = 0 ) { |
| 19 | | $contents = file_get_contents( $file ); |
| 20 | | $upload = wp_upload_bits( basename( $file ), null, $contents ); |
| 21 | | |
| 22 | | return parent::_make_attachment( $upload, $parent_post_id ); |
| 23 | | } |
| 24 | | |
| 25 | 18 | function test_make_intermediate_size_no_size() { |
| 26 | 19 | $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false ); |
| 27 | 20 | |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 71 | 64 | function test_get_intermediate_sizes_by_name() { |
| 72 | 65 | add_image_size( 'test-size', 330, 220, true ); |
| 73 | 66 | |
| 74 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 75 | | $id = $this->_make_attachment( $file, 0 ); |
| | 67 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 76 | 68 | |
| 77 | 69 | // look for a size by name |
| 78 | 70 | $image = image_get_intermediate_size( $id, 'test-size' ); |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 94 | 86 | add_image_size( 'false-height', 330, 400, true ); |
| 95 | 87 | add_image_size( 'false-width', 600, 220, true ); |
| 96 | 88 | |
| 97 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 98 | | $id = $this->_make_attachment( $file, 0 ); |
| | 89 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 99 | 90 | |
| 100 | 91 | // look for a size by array that exists |
| 101 | 92 | // note: staying larger than 300px to miss default medium crop |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 116 | 107 | add_image_size( 'false-height', 330, 100, true ); |
| 117 | 108 | add_image_size( 'false-width', 150, 220, true ); |
| 118 | 109 | |
| 119 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 120 | | $id = $this->_make_attachment( $file, 0 ); |
| | 110 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 121 | 111 | |
| 122 | 112 | // look for a size by array that doesn't exist |
| 123 | 113 | // note: staying larger than 300px to miss default medium crop |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 137 | 127 | add_image_size( 'false-height', 330, 100, true ); |
| 138 | 128 | add_image_size( 'false-width', 150, 220, true ); |
| 139 | 129 | |
| 140 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 141 | | $id = $this->_make_attachment( $file, 0 ); |
| | 130 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 142 | 131 | |
| 143 | 132 | // look for a size by array that doesn't exist |
| 144 | 133 | // note: staying larger than 300px to miss default medium crop |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 160 | 149 | add_image_size( 'test-size', $random_w, 0, false ); |
| 161 | 150 | add_image_size( 'false-height', $random_w, 100, true ); |
| 162 | 151 | |
| 163 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 164 | | $id = $this->_make_attachment( $file, 0 ); |
| | 152 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 165 | 153 | |
| 166 | 154 | $original = wp_get_attachment_metadata( $id ); |
| 167 | 155 | $image_w = $random_w; |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 188 | 176 | add_image_size( 'test-size', 0, $height, false ); |
| 189 | 177 | add_image_size( 'false-height', 300, $height, true ); |
| 190 | 178 | |
| 191 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 192 | | $id = $this->_make_attachment( $file, 0 ); |
| | 179 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 193 | 180 | |
| 194 | 181 | $original = wp_get_attachment_metadata( $id ); |
| 195 | 182 | $image_h = $height; |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 214 | 201 | $height = 201; |
| 215 | 202 | add_image_size( 'off-by-one', $width, $height, true ); |
| 216 | 203 | |
| 217 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 218 | | $id = $this->_make_attachment( $file, 0 ); |
| | 204 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 219 | 205 | |
| 220 | 206 | $original = wp_get_attachment_metadata( $id ); |
| 221 | 207 | $image_h = $height; |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 235 | 221 | // Add a hard cropped size that matches the aspect ratio we're going to test. |
| 236 | 222 | add_image_size( 'test-size', 200, 100, true ); |
| 237 | 223 | |
| 238 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 239 | | $id = $this->_make_attachment( $file, 0 ); |
| | 224 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 240 | 225 | |
| 241 | 226 | // Request a size by array that doesn't exist and is smaller than the 'thumbnail' |
| 242 | 227 | $image = image_get_intermediate_size( $id, array( 50, 25 ) ); |
| … |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
| 249 | 234 | * @ticket 34384 |
| 250 | 235 | */ |
| 251 | 236 | public function test_get_intermediate_size_with_small_size_array_fallback() { |
| 252 | | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| 253 | | $id = $this->_make_attachment( $file, 0 ); |
| | 237 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 254 | 238 | |
| 255 | 239 | $original = wp_get_attachment_metadata( $id ); |
| 256 | 240 | $thumbnail_file = $original['sizes']['thumbnail']['file']; |
diff --git tests/phpunit/tests/image/siteIcon.php tests/phpunit/tests/image/siteIcon.php
index 509b69f975..974dfe6b04 100644
|
|
|
class Tests_WP_Site_Icon extends WP_UnitTestCase { |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | function _insert_attachment() { |
| 159 | | if ( $this->attachment_id ) { |
| 160 | | return $this->attachment_id; |
| | 159 | if ( ! $this->attachment_id ) { |
| | 160 | $this->attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | | $filename = DIR_TESTDATA . '/images/test-image.jpg'; |
| 164 | | $contents = file_get_contents( $filename ); |
| 165 | | |
| 166 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 167 | | |
| 168 | | $this->attachment_id = $this->_make_attachment( $upload ); |
| 169 | 163 | return $this->attachment_id; |
| 170 | 164 | } |
| 171 | 165 | } |
diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php
index 08e44500f8..21813ab02f 100644
|
|
|
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | function test_insert_image_no_thumb() { |
| 25 | | |
| 26 | 25 | // 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 ); |
| | 26 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 34 | 27 | |
| 35 | 28 | // intermediate copies should not exist |
| 36 | 29 | $this->assertFalse( image_get_intermediate_size( $id, 'thumbnail' ) ); |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 39 | 32 | |
| 40 | 33 | // medium, medium_large, and full size will both point to the original |
| 41 | 34 | $downsize = image_downsize( $id, 'medium' ); |
| 42 | | $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); |
| | 35 | $this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) ); |
| 43 | 36 | $this->assertEquals( 50, $downsize[1] ); |
| 44 | 37 | $this->assertEquals( 50, $downsize[2] ); |
| 45 | 38 | |
| 46 | 39 | $downsize = image_downsize( $id, 'medium_large' ); |
| 47 | | $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); |
| | 40 | $this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) ); |
| 48 | 41 | $this->assertEquals( 50, $downsize[1] ); |
| 49 | 42 | $this->assertEquals( 50, $downsize[2] ); |
| 50 | 43 | |
| 51 | 44 | $downsize = image_downsize( $id, 'full' ); |
| 52 | | $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); |
| | 45 | $this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) ); |
| 53 | 46 | $this->assertEquals( 50, $downsize[1] ); |
| 54 | 47 | $this->assertEquals( 50, $downsize[2] ); |
| 55 | 48 | |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 63 | 56 | update_option( 'medium_size_w', 0 ); |
| 64 | 57 | update_option( 'medium_size_h', 0 ); |
| 65 | 58 | |
| 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 ); |
| | 59 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/a2-small.jpg' );; |
| 73 | 60 | |
| 74 | 61 | // intermediate copies should exist: thumbnail only |
| 75 | 62 | $thumb = image_get_intermediate_size( $id, 'thumbnail' ); |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 119 | 106 | update_option( 'medium_large_size_w', 600 ); |
| 120 | 107 | update_option( 'medium_large_size_h', 0 ); |
| 121 | 108 | |
| 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 ); |
| | 109 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' ); |
| 129 | 110 | $uploads = wp_upload_dir(); |
| 130 | 111 | |
| 131 | 112 | // intermediate copies should exist: thumbnail and medium |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 178 | 159 | update_option( 'medium_large_size_w', 600 ); |
| 179 | 160 | update_option( 'medium_large_size_h', 0 ); |
| 180 | 161 | |
| 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 ); |
| | 162 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );; |
| 188 | 163 | $uploads = wp_upload_dir(); |
| 189 | 164 | |
| 190 | 165 | // check that the file and intermediates exist |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 220 | 195 | * @ticket 21963 |
| 221 | 196 | */ |
| 222 | 197 | function test_insert_image_without_guid() { |
| 223 | | // this image is smaller than the thumbnail size so it won't have one |
| 224 | | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 225 | | $contents = file_get_contents( $filename ); |
| | 198 | $attachment_id = self::factory()->attachment->create( array( 'file' => '' ) ); |
| 226 | 199 | |
| 227 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 228 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 229 | | |
| 230 | | $upload['url'] = ''; |
| 231 | | $id = $this->_make_attachment( $upload ); |
| | 200 | $guid = get_the_guid( $attachment_id ); |
| 232 | 201 | |
| 233 | | $guid = get_the_guid( $id ); |
| 234 | 202 | $this->assertFalse( empty( $guid ) ); |
| | 203 | $this->assertContains( '?attachment_id=' . $attachment_id, $guid ); |
| 235 | 204 | } |
| 236 | 205 | |
| 237 | 206 | /** |
| 238 | 207 | * @ticket 21963 |
| 239 | 208 | */ |
| 240 | 209 | function test_update_attachment_fields() { |
| 241 | | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 242 | | $contents = file_get_contents( $filename ); |
| 243 | | |
| 244 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 245 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 246 | | |
| 247 | | $id = $this->_make_attachment( $upload ); |
| | 210 | $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 248 | 211 | |
| 249 | 212 | $attached_file = get_post_meta( $id, '_wp_attached_file', true ); |
| 250 | 213 | |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 264 | 227 | * @ticket 29646 |
| 265 | 228 | */ |
| 266 | 229 | function test_update_orphan_attachment_parent() { |
| 267 | | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 268 | | $contents = file_get_contents( $filename ); |
| 269 | | |
| 270 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 271 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 272 | | |
| 273 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 230 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 274 | 231 | |
| 275 | 232 | // Assert that the attachment is an orphan |
| 276 | 233 | $attachment = get_post( $attachment_id ); |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 296 | 253 | $siteurl = get_option( 'siteurl' ); |
| 297 | 254 | update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) ); |
| 298 | 255 | |
| 299 | | $filename = DIR_TESTDATA . '/images/test-image.jpg'; |
| 300 | | $contents = file_get_contents( $filename ); |
| 301 | | |
| 302 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 303 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 304 | | |
| 305 | | // Set attachment ID. |
| 306 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 256 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 307 | 257 | |
| 308 | 258 | $_SERVER['HTTPS'] = 'off'; |
| 309 | 259 | |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 321 | 271 | $siteurl = get_option( 'siteurl' ); |
| 322 | 272 | update_option( 'siteurl', set_url_scheme( $siteurl, 'https' ) ); |
| 323 | 273 | |
| 324 | | $filename = DIR_TESTDATA . '/images/test-image.jpg'; |
| 325 | | $contents = file_get_contents( $filename ); |
| 326 | | |
| 327 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 328 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 329 | | |
| 330 | 274 | // Set attachment ID. |
| 331 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 275 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 332 | 276 | |
| 333 | 277 | $_SERVER['HTTPS'] = 'off'; |
| 334 | 278 | |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 346 | 290 | $siteurl = get_option( 'siteurl' ); |
| 347 | 291 | update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) ); |
| 348 | 292 | |
| 349 | | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 350 | | $contents = file_get_contents( $filename ); |
| 351 | | |
| 352 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 353 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 354 | | |
| 355 | 293 | // Set attachment ID |
| 356 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 294 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 357 | 295 | |
| 358 | 296 | $_SERVER['HTTPS'] = 'on'; |
| 359 | 297 | |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 374 | 312 | $siteurl = get_option( 'siteurl' ); |
| 375 | 313 | update_option( 'siteurl', set_url_scheme( $siteurl, 'https' ) ); |
| 376 | 314 | |
| 377 | | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 378 | | $contents = file_get_contents( $filename ); |
| 379 | | |
| 380 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 381 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 382 | | |
| 383 | 315 | // Set attachment ID. |
| 384 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 316 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 385 | 317 | |
| 386 | 318 | $_SERVER['HTTPS'] = 'on'; |
| 387 | 319 | |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 402 | 334 | $siteurl = get_option( 'siteurl' ); |
| 403 | 335 | update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) ); |
| 404 | 336 | |
| 405 | | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 406 | | $contents = file_get_contents( $filename ); |
| 407 | | |
| 408 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 409 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 410 | | |
| 411 | 337 | // Set attachment ID |
| 412 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 338 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 413 | 339 | |
| 414 | 340 | $_SERVER['HTTPS'] = 'on'; |
| 415 | 341 | set_current_screen( 'dashboard' ); |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 429 | 355 | // Set https upload URL |
| 430 | 356 | add_filter( 'upload_dir', '_upload_dir_https' ); |
| 431 | 357 | |
| 432 | | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 433 | | $contents = file_get_contents( $filename ); |
| 434 | | |
| 435 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 436 | | $this->assertTrue( empty( $upload['error'] ) ); |
| 437 | | |
| 438 | 358 | // Set attachment ID |
| 439 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 359 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );; |
| 440 | 360 | |
| 441 | 361 | $_SERVER['HTTPS'] = 'on'; |
| 442 | 362 | set_current_screen( 'dashboard' ); |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 451 | 371 | } |
| 452 | 372 | |
| 453 | 373 | public function test_wp_attachment_is() { |
| 454 | | $filename = DIR_TESTDATA . '/images/test-image.jpg'; |
| 455 | | $contents = file_get_contents( $filename ); |
| 456 | | |
| 457 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 458 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 374 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 459 | 375 | |
| 460 | 376 | $this->assertTrue( wp_attachment_is_image( $attachment_id ) ); |
| 461 | 377 | $this->assertTrue( wp_attachment_is( 'image', $attachment_id ) ); |
| … |
… |
class Tests_Post_Attachments extends WP_UnitTestCase { |
| 469 | 385 | add_filter( 'upload_mimes', array( $this, 'whitelist_psd_mime_type' ), 10, 2 ); |
| 470 | 386 | } |
| 471 | 387 | |
| 472 | | $filename = DIR_TESTDATA . '/images/test-image.psd'; |
| 473 | | $contents = file_get_contents( $filename ); |
| 474 | | |
| 475 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 476 | | $attachment_id = $this->_make_attachment( $upload ); |
| | 388 | $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.psd' ); |
| 477 | 389 | |
| 478 | 390 | $this->assertFalse( wp_attachment_is_image( $attachment_id ) ); |
| 479 | 391 | $this->assertTrue( wp_attachment_is( 'psd', $attachment_id ) ); |
diff --git tests/phpunit/tests/xmlrpc/wp/getMediaItem.php tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
index e036a7f4b9..3759343191 100644
|
|
|
class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase { |
| 18 | 18 | |
| 19 | 19 | add_theme_support( 'post-thumbnails' ); |
| 20 | 20 | |
| 21 | | $filename = ( DIR_TESTDATA . '/images/waffles.jpg' ); |
| 22 | | $contents = file_get_contents( $filename ); |
| 23 | | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 24 | | |
| 25 | | $this->attachment_id = $this->_make_attachment( $upload, self::$post_id ); |
| | 21 | $this->attachment_id = self::factory()->attachment->create_upload_object( |
| | 22 | DIR_TESTDATA . '/images/waffles.jpg', |
| | 23 | self::$post_id |
| | 24 | ); |
| 26 | 25 | $this->attachment_data = get_post( $this->attachment_id, ARRAY_A ); |
| 27 | 26 | |
| 28 | 27 | set_post_thumbnail( self::$post_id, $this->attachment_id ); |