- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets/media-video-widget.php
r41198 r42343 24 24 parent::clean_up_global_scope(); 25 25 $wp_scripts = null; 26 $wp_styles = null;26 $wp_styles = null; 27 27 } 28 28 … … 65 65 $this->assertTrue( $widget->widget_options['customize_selective_refresh'] ); 66 66 $this->assertEquals( 'video', $widget->widget_options['mime_type'] ); 67 $this->assertEqualSets( array( 68 'add_to_widget', 69 'replace_media', 70 'unsupported_file_type', 71 'edit_media', 72 'media_library_state_multi', 73 'media_library_state_single', 74 'missing_attachment', 75 'no_media_selected', 76 'add_media', 77 ), array_keys( $widget->l10n ) ); 67 $this->assertEqualSets( 68 array( 69 'add_to_widget', 70 'replace_media', 71 'unsupported_file_type', 72 'edit_media', 73 'media_library_state_multi', 74 'media_library_state_single', 75 'missing_attachment', 76 'no_media_selected', 77 'add_media', 78 ), array_keys( $widget->l10n ) 79 ); 78 80 } 79 81 … … 84 86 */ 85 87 function test_update() { 86 $widget = new WP_Widget_Media_Video();88 $widget = new WP_Widget_Media_Video(); 87 89 $instance = array(); 88 90 … … 91 93 'attachment_id' => 1, 92 94 ); 93 $result = $widget->update( $expected, $instance );95 $result = $widget->update( $expected, $instance ); 94 96 $this->assertSame( $result, $expected ); 95 97 96 98 // Should filter invalid attachment ID. 97 $result = $widget->update( array( 98 'attachment_id' => 'media', 99 ), $instance ); 99 $result = $widget->update( 100 array( 101 'attachment_id' => 'media', 102 ), $instance 103 ); 100 104 $this->assertSame( $result, $instance ); 101 105 … … 104 108 'url' => 'https://chickenandribs.org', 105 109 ); 106 $result = $widget->update( $expected, $instance );110 $result = $widget->update( $expected, $instance ); 107 111 $this->assertSame( $result, $expected ); 108 112 109 113 // Should filter invalid attachment url. 110 $result = $widget->update( array( 111 'url' => 'not_a_url', 112 ), $instance ); 114 $result = $widget->update( 115 array( 116 'url' => 'not_a_url', 117 ), $instance 118 ); 113 119 $this->assertNotSame( $result, $instance ); 114 120 $this->assertStringStartsWith( 'http://', $result['url'] ); … … 118 124 'loop' => true, 119 125 ); 120 $result = $widget->update( $expected, $instance );126 $result = $widget->update( $expected, $instance ); 121 127 $this->assertSame( $result, $expected ); 122 128 123 129 // Should filter invalid loop setting. 124 $result = $widget->update( array( 125 'loop' => 'not-boolean', 126 ), $instance ); 130 $result = $widget->update( 131 array( 132 'loop' => 'not-boolean', 133 ), $instance 134 ); 127 135 $this->assertSame( $result, $instance ); 128 136 … … 131 139 'title' => 'A video of goats', 132 140 ); 133 $result = $widget->update( $expected, $instance );141 $result = $widget->update( $expected, $instance ); 134 142 $this->assertSame( $result, $expected ); 135 143 136 144 // Should filter invalid attachment title. 137 $result = $widget->update( array( 138 'title' => '<h1>Cute Baby Goats</h1>', 139 ), $instance ); 145 $result = $widget->update( 146 array( 147 'title' => '<h1>Cute Baby Goats</h1>', 148 ), $instance 149 ); 140 150 $this->assertNotSame( $result, $instance ); 141 151 … … 144 154 'preload' => 'none', 145 155 ); 146 $result = $widget->update( $expected, $instance );156 $result = $widget->update( $expected, $instance ); 147 157 $this->assertSame( $result, $expected ); 148 158 149 159 // Should filter invalid preload setting. 150 $result = $widget->update( array( 151 'preload' => 'nope', 152 ), $instance ); 160 $result = $widget->update( 161 array( 162 'preload' => 'nope', 163 ), $instance 164 ); 153 165 $this->assertSame( $result, $instance ); 154 166 155 167 // Should filter invalid key. 156 $result = $widget->update( array( 157 'h4x' => 'value', 158 ), $instance ); 168 $result = $widget->update( 169 array( 170 'h4x' => 'value', 171 ), $instance 172 ); 159 173 $this->assertSame( $result, $instance ); 160 174 } … … 168 182 function test_render_media() { 169 183 $test_movie_file = __FILE__ . '../../data/uploads/small-video.m4v'; 170 $widget = new WP_Widget_Media_Video(); 171 $attachment_id = self::factory()->attachment->create_object( array( 172 'file' => $test_movie_file, 173 'post_parent' => 0, 174 'post_mime_type' => 'video/mp4', 175 'post_title' => 'Test Video', 176 ) ); 184 $widget = new WP_Widget_Media_Video(); 185 $attachment_id = self::factory()->attachment->create_object( 186 array( 187 'file' => $test_movie_file, 188 'post_parent' => 0, 189 'post_mime_type' => 'video/mp4', 190 'post_title' => 'Test Video', 191 ) 192 ); 177 193 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $test_movie_file ) ); 178 194 … … 185 201 // Should be empty when there is an invalid attachment_id. 186 202 ob_start(); 187 $widget->render_media( array( 188 'attachment_id' => 777, 189 ) ); 203 $widget->render_media( 204 array( 205 'attachment_id' => 777, 206 ) 207 ); 190 208 $output = ob_get_clean(); 191 209 $this->assertEmpty( $output ); … … 193 211 // Tests with video from library. 194 212 ob_start(); 195 $widget->render_media( array( 196 'attachment_id' => $attachment_id, 197 ) ); 213 $widget->render_media( 214 array( 215 'attachment_id' => $attachment_id, 216 ) 217 ); 198 218 $output = ob_get_clean(); 199 219 … … 207 227 208 228 ob_start(); 209 $widget->render_media( array( 210 'attachment_id' => $attachment_id, 211 'title' => 'Open Source Cartoon', 212 'preload' => 'metadata', 213 'loop' => true, 214 ) ); 229 $widget->render_media( 230 array( 231 'attachment_id' => $attachment_id, 232 'title' => 'Open Source Cartoon', 233 'preload' => 'metadata', 234 'loop' => true, 235 ) 236 ); 215 237 $output = ob_get_clean(); 216 238 … … 222 244 ob_start(); 223 245 $content = '<track srclang="en" label="English" kind="subtitles" src="http://example.com/wp-content/uploads/2017/04/subtitles-en.vtt">'; 224 $widget->render_media( array( 225 'attachment_id' => null, 226 'loop' => false, 227 'url' => 'https://www.youtube.com/watch?v=OQSNhk5ICTI', 228 'content' => $content, 229 ) ); 246 $widget->render_media( 247 array( 248 'attachment_id' => null, 249 'loop' => false, 250 'url' => 'https://www.youtube.com/watch?v=OQSNhk5ICTI', 251 'content' => $content, 252 ) 253 ); 230 254 $output = ob_get_clean(); 231 255 … … 248 272 249 273 $wp_scripts = null; 250 $wp_styles = null;274 $wp_styles = null; 251 275 $widget->enqueue_preview_scripts(); 252 276 $this->assertTrue( wp_script_is( 'wp-mediaelement' ) ); … … 255 279 256 280 $wp_scripts = null; 257 $wp_styles = null;281 $wp_styles = null; 258 282 add_filter( 'wp_video_shortcode_library', '__return_empty_string' ); 259 283 $widget->enqueue_preview_scripts();
Note: See TracChangeset
for help on using the changeset viewer.