Changeset 42343 for trunk/tests/phpunit/tests/post/thumbnails.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/post/thumbnails.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/thumbnails.php
r41693 r42343 10 10 protected static $attachment_id; 11 11 12 protected $current_size_filter_data = null;12 protected $current_size_filter_data = null; 13 13 protected $current_size_filter_result = null; 14 14 … … 17 17 self::$different_post = $factory->post->create_and_get(); 18 18 19 $file = DIR_TESTDATA . '/images/canola.jpg'; 20 self::$attachment_id = $factory->attachment->create_upload_object( $file, self::$post->ID, array( 21 'post_mime_type' => 'image/jpeg', 22 ) ); 19 $file = DIR_TESTDATA . '/images/canola.jpg'; 20 self::$attachment_id = $factory->attachment->create_upload_object( 21 $file, self::$post->ID, array( 22 'post_mime_type' => 'image/jpeg', 23 ) 24 ); 23 25 } 24 26 … … 68 70 set_post_thumbnail( self::$post, self::$attachment_id ); 69 71 70 $WP_Query = new WP_Query( array( 71 'post_type' => 'any', 72 'post__in' => array( self::$post->ID ), 73 'orderby' => 'post__in', 74 ) ); 72 $WP_Query = new WP_Query( 73 array( 74 'post_type' => 'any', 75 'post__in' => array( self::$post->ID ), 76 'orderby' => 'post__in', 77 ) 78 ); 75 79 76 80 $this->assertFalse( $WP_Query->thumbnails_cached ); … … 89 93 $caption = 'This is a caption.'; 90 94 91 $post_id = self::factory()->post->create(); 92 $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array( 93 'post_mime_type' => 'image/jpeg', 94 'post_type' => 'attachment', 95 'post_excerpt' => $caption, 96 ) ); 95 $post_id = self::factory()->post->create(); 96 $attachment_id = self::factory()->attachment->create_object( 97 'image.jpg', $post_id, array( 98 'post_mime_type' => 'image/jpeg', 99 'post_type' => 'attachment', 100 'post_excerpt' => $caption, 101 ) 102 ); 97 103 98 104 set_post_thumbnail( $post_id, $attachment_id ); … … 105 111 */ 106 112 function test_get_the_post_thumbnail_caption_empty() { 107 $post_id = self::factory()->post->create(); 108 $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array( 109 'post_mime_type' => 'image/jpeg', 110 'post_type' => 'attachment', 111 'post_excerpt' => '', 112 ) ); 113 $post_id = self::factory()->post->create(); 114 $attachment_id = self::factory()->attachment->create_object( 115 'image.jpg', $post_id, array( 116 'post_mime_type' => 'image/jpeg', 117 'post_type' => 'attachment', 118 'post_excerpt' => '', 119 ) 120 ); 113 121 114 122 set_post_thumbnail( $post_id, $attachment_id ); … … 123 131 $caption = 'This is a caption.'; 124 132 125 $post_id = self::factory()->post->create(); 126 $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array( 127 'post_mime_type' => 'image/jpeg', 128 'post_type' => 'attachment', 129 'post_excerpt' => $caption, 130 ) ); 133 $post_id = self::factory()->post->create(); 134 $attachment_id = self::factory()->attachment->create_object( 135 'image.jpg', $post_id, array( 136 'post_mime_type' => 'image/jpeg', 137 'post_type' => 'attachment', 138 'post_excerpt' => $caption, 139 ) 140 ); 131 141 132 142 set_post_thumbnail( $post_id, $attachment_id ); … … 143 153 set_post_thumbnail( self::$post, self::$attachment_id ); 144 154 145 $expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array( 146 'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image' 147 ) ); 155 $expected = wp_get_attachment_image( 156 self::$attachment_id, 'post-thumbnail', false, array( 157 'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image', 158 ) 159 ); 148 160 149 161 $this->assertEquals( $expected, get_the_post_thumbnail( self::$post ) ); … … 171 183 set_post_thumbnail( self::$post, self::$attachment_id ); 172 184 173 $expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array( 174 'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image' 175 ) ); 185 $expected = wp_get_attachment_image( 186 self::$attachment_id, 'post-thumbnail', false, array( 187 'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image', 188 ) 189 ); 176 190 177 191 ob_start(); … … 247 261 $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null; 248 262 249 $GLOBALS['post'] = self::$post;263 $GLOBALS['post'] = self::$post; 250 264 $_REQUEST['_thumbnail_id'] = self::$attachment_id; 251 $_REQUEST['preview_id'] = self::$post->ID;265 $_REQUEST['preview_id'] = self::$post->ID; 252 266 253 267 $result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' ); … … 267 281 $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null; 268 282 269 $secondary_post = self::factory()->post->create( array( 283 $secondary_post = self::factory()->post->create( 284 array( 270 285 'post_stauts' => 'publish', 271 286 ) 272 287 ); 273 288 274 $GLOBALS['post'] = self::$post;289 $GLOBALS['post'] = self::$post; 275 290 $_REQUEST['_thumbnail_id'] = self::$attachment_id; 276 $_REQUEST['preview_id'] = $secondary_post;291 $_REQUEST['preview_id'] = $secondary_post; 277 292 278 293 $result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' ); … … 290 305 */ 291 306 function test_insert_post_with_post_thumbnail() { 292 $post_id = wp_insert_post( array( 293 'ID' => self::$post->ID, 294 'post_status' => 'publish', 295 'post_content' => 'Post content', 296 'post_title' => 'Post Title', 297 '_thumbnail_id' => self::$attachment_id, 298 ) ); 307 $post_id = wp_insert_post( 308 array( 309 'ID' => self::$post->ID, 310 'post_status' => 'publish', 311 'post_content' => 'Post content', 312 'post_title' => 'Post Title', 313 '_thumbnail_id' => self::$attachment_id, 314 ) 315 ); 299 316 300 317 $thumbnail_id = get_post_thumbnail_id( $post_id ); 301 318 $this->assertEquals( self::$attachment_id, $thumbnail_id ); 302 319 303 $post_id = wp_insert_post( array( 304 'ID' => $post_id, 305 'post_status' => 'publish', 306 'post_content' => 'Post content', 307 'post_title' => 'Post Title', 308 '_thumbnail_id' => - 1, // -1 removes post thumbnail. 309 ) ); 320 $post_id = wp_insert_post( 321 array( 322 'ID' => $post_id, 323 'post_status' => 'publish', 324 'post_content' => 'Post content', 325 'post_title' => 'Post Title', 326 '_thumbnail_id' => - 1, // -1 removes post thumbnail. 327 ) 328 ); 310 329 311 330 $thumbnail_id = get_post_thumbnail_id( $post_id ); … … 318 337 function test_insert_attachment_with_post_thumbnail() { 319 338 // Audio files support featured images. 320 $post_id = wp_insert_post( array( 321 'post_type' => 'attachment', 322 'post_status' => 'inherit', 323 'post_content' => 'Post content', 324 'post_title' => 'Post Title', 325 'post_mime_type' => 'audio/mpeg', 326 'post_parent' => 0, 327 'file' => DIR_TESTDATA . '/audio/test-noise.mp3', // File does not exist, but does not matter here. 328 '_thumbnail_id' => self::$attachment_id, 329 ) ); 339 $post_id = wp_insert_post( 340 array( 341 'post_type' => 'attachment', 342 'post_status' => 'inherit', 343 'post_content' => 'Post content', 344 'post_title' => 'Post Title', 345 'post_mime_type' => 'audio/mpeg', 346 'post_parent' => 0, 347 'file' => DIR_TESTDATA . '/audio/test-noise.mp3', // File does not exist, but does not matter here. 348 '_thumbnail_id' => self::$attachment_id, 349 ) 350 ); 330 351 331 352 $thumbnail_id = get_post_thumbnail_id( $post_id ); … … 333 354 334 355 // Images do not support featured images. 335 $post_id = wp_insert_post( array( 336 'post_type' => 'attachment', 337 'post_status' => 'inherit', 338 'post_content' => 'Post content', 339 'post_title' => 'Post Title', 340 'post_mime_type' => 'image/jpeg', 341 'post_parent' => 0, 342 'file' => DIR_TESTDATA . '/images/canola.jpg', 343 '_thumbnail_id' => self::$attachment_id, 344 ) ); 356 $post_id = wp_insert_post( 357 array( 358 'post_type' => 'attachment', 359 'post_status' => 'inherit', 360 'post_content' => 'Post content', 361 'post_title' => 'Post Title', 362 'post_mime_type' => 'image/jpeg', 363 'post_parent' => 0, 364 'file' => DIR_TESTDATA . '/images/canola.jpg', 365 '_thumbnail_id' => self::$attachment_id, 366 ) 367 ); 345 368 346 369 $thumbnail_id = get_post_thumbnail_id( $post_id );
Note: See TracChangeset
for help on using the changeset viewer.