Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/wp-admin/includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -3194,7 +3194,11 @@ function edit_form_image_editor( $post ) {

wp_maybe_generate_attachment_metadata( $post );

echo wp_audio_shortcode( array( 'src' => $att_url ) );
$preview = wp_audio_shortcode( array( 'src' => $att_url ) );

if ( ! str_contains( $preview, 'class="wp-embedded-audio"' ) ) :
echo $preview;
endif;

elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ) :

Expand All @@ -3221,7 +3225,11 @@ function edit_form_image_editor( $post ) {
$attr['poster'] = wp_get_attachment_url( $thumb_id );
}

echo wp_video_shortcode( $attr );
$preview = wp_video_shortcode( $attr );

if ( ! str_contains( $preview, 'class="wp-embedded-video"' ) ) :
echo $preview;
endif;

elseif ( isset( $thumb_url[0] ) ) :
?>
Expand Down
89 changes: 89 additions & 0 deletions tests/phpunit/tests/admin/includesMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

/**
* @group admin
*/
class Tests_Admin_IncludesMedia extends WP_UnitTestCase {
/**
* The ID of an administrator user.
*
* @var int
*/
protected static $admin_id;

public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
require_once ABSPATH . 'wp-admin/includes/media.php';

self::$admin_id = $factory->user->create(
array(
'role' => 'administrator',
)
);
}

public function set_up(): void {
parent::set_up();

wp_set_current_user( self::$admin_id );
set_current_screen( 'post.php' );
}

public function tear_down(): void {
unset( $_GET['image-editor'] );
parent::tear_down();
}

/**
* @ticket 64929
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_edit_form_image_editor_skips_fallback_link_for_non_previewable_video() {
$attachment_id = $this->create_upload_attachment_from_contents( 'sample.avi', 'RIFF0000AVI LIST' );
$post = get_post( $attachment_id );

ob_start();
edit_form_image_editor( $post );
$markup = ob_get_clean();

$this->assertStringNotContainsString( 'wp-embedded-video', $markup );
$this->assertStringNotContainsString( wp_get_attachment_url( $attachment_id ), $markup );
}

/**
* @ticket 64929
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_edit_form_image_editor_keeps_preview_for_supported_video() {
$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/uploads/small-video.mp4' );
$post = get_post( $attachment_id );

ob_start();
edit_form_image_editor( $post );
$markup = ob_get_clean();

$this->assertStringContainsString( '<video', $markup );
$this->assertStringNotContainsString( 'wp-embedded-video', $markup );
}

/**
* Creates an uploaded attachment from raw file contents.
*
* @param string $filename The file name to use for the upload.
* @param string $contents The file contents.
* @return int Attachment ID.
*/
private function create_upload_attachment_from_contents( $filename, $contents ) {
$temp_file = trailingslashit( get_temp_dir() ) . wp_generate_password( 8, false ) . '-' . $filename;
file_put_contents( $temp_file, $contents );

$attachment_id = self::factory()->attachment->create_upload_object( $temp_file );

unlink( $temp_file );

$this->assertIsInt( $attachment_id );

return $attachment_id;
}
}
Loading