mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Post Thumbnails: Restore thumbnail support for media files.
* Allow to add/remove a featured image to `attachment:audio` and `attachment:video` post types, see [27657]. * Change conditionals to check for theme OR post type support. * Add tests for #12922. Broken in [37658]. Props flixos90, joemcgill, DrewAPicture, wonderboymusic. See #12922. Fixes #37658. git-svn-id: https://develop.svn.wordpress.org/trunk@38263 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -233,4 +233,86 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 12922
|
||||
*/
|
||||
function test__wp_preview_post_thumbnail_filter() {
|
||||
$old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
|
||||
|
||||
$GLOBALS['post'] = self::$post;
|
||||
$_REQUEST['_thumbnail_id'] = self::$attachment_id;
|
||||
|
||||
$result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' );
|
||||
$this->assertEquals( self::$attachment_id, $result );
|
||||
|
||||
unset( $_REQUEST['_thumbnail_id'] );
|
||||
if ( null === $old_post ) {
|
||||
unset( $GLOBALS['post'] );
|
||||
} else {
|
||||
$GLOBALS['post'] = $old_post;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 12922
|
||||
*/
|
||||
function test_insert_post_with_post_thumbnail() {
|
||||
$post_id = wp_insert_post( array(
|
||||
'ID' => self::$post->ID,
|
||||
'post_status' => 'publish',
|
||||
'post_content' => rand_str(),
|
||||
'post_title' => rand_str(),
|
||||
'_thumbnail_id' => self::$attachment_id,
|
||||
) );
|
||||
|
||||
$thumbnail_id = get_post_thumbnail_id( $post_id );
|
||||
$this->assertEquals( self::$attachment_id, $thumbnail_id );
|
||||
|
||||
$post_id = wp_insert_post( array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'publish',
|
||||
'post_content' => rand_str(),
|
||||
'post_title' => rand_str(),
|
||||
'_thumbnail_id' => - 1, // -1 removes post thumbnail.
|
||||
) );
|
||||
|
||||
$thumbnail_id = get_post_thumbnail_id( $post_id );
|
||||
$this->assertEmpty( $thumbnail_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37658
|
||||
*/
|
||||
function test_insert_attachment_with_post_thumbnail() {
|
||||
// Audio files support featured images.
|
||||
$post_id = wp_insert_post( array(
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'post_content' => rand_str(),
|
||||
'post_title' => rand_str(),
|
||||
'post_mime_type' => 'audio/mpeg',
|
||||
'post_parent' => 0,
|
||||
'file' => DIR_TESTDATA . '/audio/test-noise.mp3', // File does not exist, but does not matter here.
|
||||
'_thumbnail_id' => self::$attachment_id,
|
||||
) );
|
||||
|
||||
$thumbnail_id = get_post_thumbnail_id( $post_id );
|
||||
$this->assertEquals( self::$attachment_id, $thumbnail_id );
|
||||
|
||||
// Images do not support featured images.
|
||||
$post_id = wp_insert_post( array(
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'post_content' => rand_str(),
|
||||
'post_title' => rand_str(),
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'post_parent' => 0,
|
||||
'file' => DIR_TESTDATA . '/images/canola.jpg',
|
||||
'_thumbnail_id' => self::$attachment_id,
|
||||
) );
|
||||
|
||||
$thumbnail_id = get_post_thumbnail_id( $post_id );
|
||||
$this->assertEmpty( $thumbnail_id );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user