| | 236 | |
| | 237 | /** |
| | 238 | * @ticket 12922 |
| | 239 | */ |
| | 240 | function test__wp_preview_post_thumbnail_filter() { |
| | 241 | $post_id = self::factory()->post->create(); |
| | 242 | |
| | 243 | $_REQUEST['_thumbnail_id'] = self::$attachment_id; |
| | 244 | |
| | 245 | $result = _wp_preview_post_thumbnail_filter( '', $post_id, '_thumbnail_id' ); |
| | 246 | $this->assertEquals( self::$attachment_id, $result ); |
| | 247 | } |
| | 248 | |
| | 249 | /** |
| | 250 | * @ticket 12922 |
| | 251 | */ |
| | 252 | function test_insert_post_with_post_thumbnail() { |
| | 253 | $post_id = wp_insert_post( array( |
| | 254 | 'post_status' => 'publish', |
| | 255 | 'post_content' => rand_str(), |
| | 256 | 'post_title' => rand_str(), |
| | 257 | '_thumbnail_id' => self::$attachment_id, |
| | 258 | ) ); |
| | 259 | |
| | 260 | $thumbnail_id = get_post_thumbnail_id( $post_id ); |
| | 261 | $this->assertEquals( self::$attachment_id, $thumbnail_id ); |
| | 262 | |
| | 263 | $post_id = wp_insert_post( array( |
| | 264 | 'ID' => $post_id, |
| | 265 | 'post_status' => 'publish', |
| | 266 | 'post_content' => rand_str(), |
| | 267 | 'post_title' => rand_str(), |
| | 268 | '_thumbnail_id' => -1, // -1 removes post thumbnail. |
| | 269 | ) ); |
| | 270 | |
| | 271 | $thumbnail_id = get_post_thumbnail_id( $post_id ); |
| | 272 | $this->assertEmpty( $thumbnail_id ); |
| | 273 | } |
| | 274 | |
| | 275 | /** |
| | 276 | * @ticket 37658 |
| | 277 | */ |
| | 278 | function test_insert_attachment_with_post_thumbnail() { |
| | 279 | // Audio files support featured images. |
| | 280 | $post_id = wp_insert_post( array( |
| | 281 | 'post_type' => 'attachment', |
| | 282 | 'post_status' => 'publish', |
| | 283 | 'post_content' => rand_str(), |
| | 284 | 'post_title' => rand_str(), |
| | 285 | 'post_mime_type' => 'audio/mpeg', |
| | 286 | 'post_parent' => 0, |
| | 287 | 'file' => DIR_TESTDATA . '/images/canola.jpg', |
| | 288 | '_thumbnail_id' => self::$attachment_id, |
| | 289 | ) ); |
| | 290 | |
| | 291 | $thumbnail_id = get_post_thumbnail_id( $post_id ); |
| | 292 | $this->assertEquals( self::$attachment_id, $thumbnail_id ); |
| | 293 | |
| | 294 | // Images do not support featured images. |
| | 295 | $post_id = wp_insert_post( array( |
| | 296 | 'post_type' => 'attachment', |
| | 297 | 'post_status' => 'publish', |
| | 298 | 'post_content' => rand_str(), |
| | 299 | 'post_title' => rand_str(), |
| | 300 | 'post_mime_type' => 'image/jpeg', |
| | 301 | 'post_parent' => 0, |
| | 302 | 'file' => DIR_TESTDATA . '/images/canola.jpg', |
| | 303 | '_thumbnail_id' => self::$attachment_id, |
| | 304 | ) ); |
| | 305 | |
| | 306 | $thumbnail_id = get_post_thumbnail_id( $post_id ); |
| | 307 | $this->assertEmpty( $thumbnail_id ); |
| | 308 | } |