- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets/media-audio-widget.php
r40640 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 … … 34 34 function test_get_instance_schema() { 35 35 $wp_widget_audio = new WP_Widget_Media_Audio(); 36 $schema = $wp_widget_audio->get_instance_schema();36 $schema = $wp_widget_audio->get_instance_schema(); 37 37 38 38 $this->assertEqualSets( … … 64 64 $this->assertTrue( $widget->widget_options['customize_selective_refresh'] ); 65 65 $this->assertEquals( 'audio', $widget->widget_options['mime_type'] ); 66 $this->assertEqualSets( array( 67 'add_to_widget', 68 'replace_media', 69 'edit_media', 70 'media_library_state_multi', 71 'media_library_state_single', 72 'missing_attachment', 73 'no_media_selected', 74 'add_media', 75 'unsupported_file_type', 76 ), array_keys( $widget->l10n ) ); 66 $this->assertEqualSets( 67 array( 68 'add_to_widget', 69 'replace_media', 70 'edit_media', 71 'media_library_state_multi', 72 'media_library_state_single', 73 'missing_attachment', 74 'no_media_selected', 75 'add_media', 76 'unsupported_file_type', 77 ), array_keys( $widget->l10n ) 78 ); 77 79 } 78 80 … … 83 85 */ 84 86 function test_update() { 85 $widget = new WP_Widget_Media_Audio();87 $widget = new WP_Widget_Media_Audio(); 86 88 $instance = array(); 87 89 … … 90 92 'attachment_id' => 1, 91 93 ); 92 $result = $widget->update( $expected, $instance );94 $result = $widget->update( $expected, $instance ); 93 95 $this->assertSame( $result, $expected ); 94 96 95 97 // Should filter invalid attachment ID. 96 $result = $widget->update( array( 97 'attachment_id' => 'media', 98 ), $instance ); 98 $result = $widget->update( 99 array( 100 'attachment_id' => 'media', 101 ), $instance 102 ); 99 103 $this->assertSame( $result, $instance ); 100 104 … … 103 107 'url' => 'https://chickenandribs.org', 104 108 ); 105 $result = $widget->update( $expected, $instance );109 $result = $widget->update( $expected, $instance ); 106 110 $this->assertSame( $result, $expected ); 107 111 108 112 // Should filter invalid attachment url. 109 $result = $widget->update( array( 110 'url' => 'not_a_url', 111 ), $instance ); 113 $result = $widget->update( 114 array( 115 'url' => 'not_a_url', 116 ), $instance 117 ); 112 118 $this->assertNotSame( $result, $instance ); 113 119 $this->assertStringStartsWith( 'http://', $result['url'] ); … … 117 123 'loop' => true, 118 124 ); 119 $result = $widget->update( $expected, $instance );125 $result = $widget->update( $expected, $instance ); 120 126 $this->assertSame( $result, $expected ); 121 127 122 128 // Should filter invalid loop setting. 123 $result = $widget->update( array( 124 'loop' => 'not-boolean', 125 ), $instance ); 129 $result = $widget->update( 130 array( 131 'loop' => 'not-boolean', 132 ), $instance 133 ); 126 134 $this->assertSame( $result, $instance ); 127 135 … … 130 138 'title' => 'An audio sample of parrots', 131 139 ); 132 $result = $widget->update( $expected, $instance );140 $result = $widget->update( $expected, $instance ); 133 141 $this->assertSame( $result, $expected ); 134 142 135 143 // Should filter invalid attachment title. 136 $result = $widget->update( array( 137 'title' => '<h1>Cute Baby Goats</h1>', 138 ), $instance ); 144 $result = $widget->update( 145 array( 146 'title' => '<h1>Cute Baby Goats</h1>', 147 ), $instance 148 ); 139 149 $this->assertNotSame( $result, $instance ); 140 150 … … 143 153 'preload' => 'none', 144 154 ); 145 $result = $widget->update( $expected, $instance );155 $result = $widget->update( $expected, $instance ); 146 156 $this->assertSame( $result, $expected ); 147 157 148 158 // Should filter invalid preload setting. 149 $result = $widget->update( array( 150 'preload' => 'nope', 151 ), $instance ); 159 $result = $widget->update( 160 array( 161 'preload' => 'nope', 162 ), $instance 163 ); 152 164 $this->assertSame( $result, $instance ); 153 165 154 166 // Should filter invalid key. 155 $result = $widget->update( array( 156 'h4x' => 'value', 157 ), $instance ); 167 $result = $widget->update( 168 array( 169 'h4x' => 'value', 170 ), $instance 171 ); 158 172 $this->assertSame( $result, $instance ); 159 173 } … … 166 180 function test_render_media() { 167 181 $test_audio_file = __FILE__ . '../../data/uploads/small-audio.mp3'; 168 $widget = new WP_Widget_Media_Audio(); 169 $attachment_id = self::factory()->attachment->create_object( array( 170 'file' => $test_audio_file, 171 'post_parent' => 0, 172 'post_mime_type' => 'audio/mp3', 173 'post_title' => 'Test Audio', 174 ) ); 182 $widget = new WP_Widget_Media_Audio(); 183 $attachment_id = self::factory()->attachment->create_object( 184 array( 185 'file' => $test_audio_file, 186 'post_parent' => 0, 187 'post_mime_type' => 'audio/mp3', 188 'post_title' => 'Test Audio', 189 ) 190 ); 175 191 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $test_audio_file ) ); 176 192 … … 183 199 // Should be empty when there is an invalid attachment_id. 184 200 ob_start(); 185 $widget->render_media( array( 186 'attachment_id' => 777, 187 ) ); 201 $widget->render_media( 202 array( 203 'attachment_id' => 777, 204 ) 205 ); 188 206 $output = ob_get_clean(); 189 207 $this->assertEmpty( $output ); … … 191 209 // Tests with audio from library. 192 210 ob_start(); 193 $widget->render_media( array( 194 'attachment_id' => $attachment_id, 195 ) ); 211 $widget->render_media( 212 array( 213 'attachment_id' => $attachment_id, 214 ) 215 ); 196 216 $output = ob_get_clean(); 197 217 … … 202 222 203 223 ob_start(); 204 $widget->render_media( array( 205 'attachment_id' => $attachment_id, 206 'title' => 'Funny', 207 'preload' => 'auto', 208 'loop' => true, 209 ) ); 224 $widget->render_media( 225 array( 226 'attachment_id' => $attachment_id, 227 'title' => 'Funny', 228 'preload' => 'auto', 229 'loop' => true, 230 ) 231 ); 210 232 $output = ob_get_clean(); 211 233 … … 225 247 global $wp_scripts, $wp_styles; 226 248 $wp_scripts = null; 227 $wp_styles = null;228 $widget = new WP_Widget_Media_Audio();249 $wp_styles = null; 250 $widget = new WP_Widget_Media_Audio(); 229 251 230 252 $this->assertFalse( wp_script_is( 'wp-mediaelement' ) );
Note: See TracChangeset
for help on using the changeset viewer.