|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @group admin |
| 5 | + */ |
| 6 | +class Tests_Admin_IncludesMedia extends WP_UnitTestCase { |
| 7 | + /** |
| 8 | + * The ID of an administrator user. |
| 9 | + * |
| 10 | + * @var int |
| 11 | + */ |
| 12 | + protected static $admin_id; |
| 13 | + |
| 14 | + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { |
| 15 | + require_once ABSPATH . 'wp-admin/includes/media.php'; |
| 16 | + |
| 17 | + self::$admin_id = $factory->user->create( |
| 18 | + array( |
| 19 | + 'role' => 'administrator', |
| 20 | + ) |
| 21 | + ); |
| 22 | + } |
| 23 | + |
| 24 | + public function set_up(): void { |
| 25 | + parent::set_up(); |
| 26 | + |
| 27 | + wp_set_current_user( self::$admin_id ); |
| 28 | + set_current_screen( 'post.php' ); |
| 29 | + } |
| 30 | + |
| 31 | + public function tear_down(): void { |
| 32 | + unset( $_GET['image-editor'] ); |
| 33 | + parent::tear_down(); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @ticket 64929 |
| 38 | + */ |
| 39 | + public function test_edit_form_image_editor_skips_fallback_link_for_non_previewable_video() { |
| 40 | + $attachment_id = $this->create_upload_attachment_from_contents( 'sample.avi', 'RIFF0000AVI LIST' ); |
| 41 | + $post = get_post( $attachment_id ); |
| 42 | + |
| 43 | + ob_start(); |
| 44 | + edit_form_image_editor( $post ); |
| 45 | + $markup = ob_get_clean(); |
| 46 | + |
| 47 | + $this->assertStringNotContainsString( 'wp-embedded-video', $markup ); |
| 48 | + $this->assertStringNotContainsString( wp_get_attachment_url( $attachment_id ), $markup ); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @ticket 64929 |
| 53 | + */ |
| 54 | + public function test_edit_form_image_editor_keeps_preview_for_supported_video() { |
| 55 | + $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/uploads/small-video.mp4' ); |
| 56 | + $post = get_post( $attachment_id ); |
| 57 | + |
| 58 | + ob_start(); |
| 59 | + edit_form_image_editor( $post ); |
| 60 | + $markup = ob_get_clean(); |
| 61 | + |
| 62 | + $this->assertStringContainsString( '<video', $markup ); |
| 63 | + $this->assertStringNotContainsString( 'wp-embedded-video', $markup ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Creates an uploaded attachment from raw file contents. |
| 68 | + * |
| 69 | + * @param string $filename The file name to use for the upload. |
| 70 | + * @param string $contents The file contents. |
| 71 | + * @return int Attachment ID. |
| 72 | + */ |
| 73 | + private function create_upload_attachment_from_contents( $filename, $contents ) { |
| 74 | + $temp_file = trailingslashit( get_temp_dir() ) . wp_generate_password( 8, false ) . '-' . $filename; |
| 75 | + file_put_contents( $temp_file, $contents ); |
| 76 | + |
| 77 | + $attachment_id = self::factory()->attachment->create_upload_object( $temp_file ); |
| 78 | + |
| 79 | + unlink( $temp_file ); |
| 80 | + |
| 81 | + $this->assertIsInt( $attachment_id ); |
| 82 | + |
| 83 | + return $attachment_id; |
| 84 | + } |
| 85 | +} |
0 commit comments