Changeset 42343 for trunk/tests/phpunit/tests/widgets/media-widget.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets/media-widget.php
r41951 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 … … 37 37 */ 38 38 function get_mocked_class_instance( $id_base = 'mocked', $name = 'Mocked', $widget_options = array(), $control_options = array() ) { 39 $original_class_name = 'WP_Widget_Media';40 $arguments = array( $id_base, $name, $widget_options, $control_options );41 $mock_class_name = '';39 $original_class_name = 'WP_Widget_Media'; 40 $arguments = array( $id_base, $name, $widget_options, $control_options ); 41 $mock_class_name = ''; 42 42 $call_original_constructor = true; 43 $call_original_clone = true;44 $call_autoload = true;45 $mocked_methods = array( 'render_media' );43 $call_original_clone = true; 44 $call_autoload = true; 45 $mocked_methods = array( 'render_media' ); 46 46 47 47 return $this->getMockForAbstractClass( $original_class_name, $arguments, $mock_class_name, $call_original_constructor, $call_original_clone, $call_autoload, $mocked_methods ); … … 63 63 $this->assertTrue( $widget->widget_options['customize_selective_refresh'] ); 64 64 $this->assertEmpty( $widget->widget_options['mime_type'] ); 65 $this->assertEqualSets( array( 66 'add_to_widget', 67 'replace_media', 68 'edit_media', 69 'media_library_state_multi', 70 'media_library_state_single', 71 'missing_attachment', 72 'no_media_selected', 73 'add_media', 74 'unsupported_file_type', 75 ), array_keys( $widget->l10n ) ); 65 $this->assertEqualSets( 66 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 ) 77 ); 76 78 $this->assertEquals( count( $widget->l10n ), count( array_filter( $widget->l10n ) ), 'Expected all translation strings to be defined.' ); 77 79 $this->assertEquals( 10, has_action( 'admin_print_scripts-widgets.php', array( $widget, 'enqueue_admin_scripts' ) ) ); … … 80 82 81 83 // With non-default args. 82 $id_base = 'media_pdf';83 $name = 'PDF';84 $widget_options = array(84 $id_base = 'media_pdf'; 85 $name = 'PDF'; 86 $widget_options = array( 85 87 'mime_type' => 'application/pdf', 86 88 ); 87 89 $control_options = array( 88 'width' => 850,90 'width' => 850, 89 91 'height' => 1100, 90 92 ); 91 $widget = $this->get_mocked_class_instance( $id_base, $name, $widget_options, $control_options );93 $widget = $this->get_mocked_class_instance( $id_base, $name, $widget_options, $control_options ); 92 94 $this->assertEquals( $id_base, $widget->id_base ); 93 95 $this->assertEquals( $name, $widget->name ); … … 109 111 function test_constructor_in_customize_preview() { 110 112 global $wp_customize; 111 wp_set_current_user( $this->factory()->user->create( array( 112 'role' => 'administrator', 113 ) ) ); 113 wp_set_current_user( 114 $this->factory()->user->create( 115 array( 116 'role' => 'administrator', 117 ) 118 ) 119 ); 114 120 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 115 $wp_customize = new WP_Customize_Manager( array( 116 'changeset_uuid' => wp_generate_uuid4(), 117 ) ); 121 $wp_customize = new WP_Customize_Manager( 122 array( 123 'changeset_uuid' => wp_generate_uuid4(), 124 ) 125 ); 118 126 $wp_customize->start_previewing_theme(); 119 127 … … 132 140 $test_image = '/tmp/canola.jpg'; 133 141 copy( DIR_TESTDATA . '/images/canola.jpg', $test_image ); 134 $attachment_id = self::factory()->attachment->create_object( array( 135 'file' => $test_image, 136 'post_parent' => 0, 137 'post_mime_type' => 'image/jpeg', 138 'post_title' => 'Canola', 139 ) ); 142 $attachment_id = self::factory()->attachment->create_object( 143 array( 144 'file' => $test_image, 145 'post_parent' => 0, 146 'post_mime_type' => 'image/jpeg', 147 'post_title' => 'Canola', 148 ) 149 ); 140 150 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $test_image ) ); 141 151 $widget = $this->get_mocked_class_instance(); … … 182 192 public function filter_instance_schema( $schema, $widget ) { 183 193 $this->filter_instance_schema_args = compact( 'schema', 'widget' ); 184 $schema['injected'] = array(194 $schema['injected'] = array( 185 195 'type' => 'boolean', 186 196 ); … … 197 207 $schema = $widget->get_instance_schema(); 198 208 199 $this->assertEqualSets( array( 200 'attachment_id', 201 'title', 202 'url', 203 ), array_keys( $schema ) ); 209 $this->assertEqualSets( 210 array( 211 'attachment_id', 212 'title', 213 'url', 214 ), array_keys( $schema ) 215 ); 204 216 205 217 // Check filter usage. … … 219 231 */ 220 232 function test_update() { 221 $widget = $this->get_mocked_class_instance();233 $widget = $this->get_mocked_class_instance(); 222 234 $instance = array(); 223 235 … … 226 238 'attachment_id' => 1, 227 239 ); 228 $result = $widget->update( $expected, $instance );240 $result = $widget->update( $expected, $instance ); 229 241 $this->assertSame( $result, $expected ); 230 242 … … 242 254 'url' => 'https://example.org', 243 255 ); 244 $result = $widget->update( $expected, $instance );256 $result = $widget->update( $expected, $instance ); 245 257 $this->assertSame( $result, $expected ); 246 258 … … 258 270 'title' => 'What a title', 259 271 ); 260 $result = $widget->update( $expected, $instance );272 $result = $widget->update( $expected, $instance ); 261 273 $this->assertSame( $result, $expected ); 262 274 … … 306 318 */ 307 319 function test_widget() { 308 $args = array(309 'before_title' => '<h2>',310 'after_title' => "</h2>\n",320 $args = array( 321 'before_title' => '<h2>', 322 'after_title' => "</h2>\n", 311 323 'before_widget' => '<section>', 312 'after_widget' => "</section>\n",324 'after_widget' => "</section>\n", 313 325 ); 314 326 $instance = array( 315 'title' => 'Foo',316 'url' => 'http://example.com/image.jpg',327 'title' => 'Foo', 328 'url' => 'http://example.com/image.jpg', 317 329 'attachment_id' => 0, 318 330 ); … … 337 349 // No title. 338 350 ob_start(); 339 $widget = $this->get_mocked_class_instance();351 $widget = $this->get_mocked_class_instance(); 340 352 $instance['title'] = ''; 341 353 $widget->expects( $this->atLeastOnce() )->method( 'render_media' )->with( $instance ); … … 345 357 346 358 // No attachment_id nor url. 347 $instance['url'] = '';359 $instance['url'] = ''; 348 360 $instance['attachment_id'] = 0; 349 361 ob_start(); … … 397 409 */ 398 410 function test_display_media_state() { 399 $widget = $this->get_mocked_class_instance(); 400 $attachment_id = self::factory()->attachment->create_object( array( 401 'file' => DIR_TESTDATA . '/images/canola.jpg', 402 'post_parent' => 0, 403 'post_mime_type' => 'image/jpeg', 404 ) ); 411 $widget = $this->get_mocked_class_instance(); 412 $attachment_id = self::factory()->attachment->create_object( 413 array( 414 'file' => DIR_TESTDATA . '/images/canola.jpg', 415 'post_parent' => 0, 416 'post_mime_type' => 'image/jpeg', 417 ) 418 ); 405 419 406 420 $result = $widget->display_media_state( array(), get_post( $attachment_id ) ); 407 421 $this->assertEqualSets( array(), $result ); 408 422 409 $widget->save_settings( array( 410 array( 411 'attachment_id' => $attachment_id, 412 ), 413 ) ); 423 $widget->save_settings( 424 array( 425 array( 426 'attachment_id' => $attachment_id, 427 ), 428 ) 429 ); 414 430 $result = $widget->display_media_state( array(), get_post( $attachment_id ) ); 415 431 $this->assertEqualSets( array( $widget->l10n['media_library_state_single'] ), $result ); 416 432 417 $widget->save_settings( array( 418 array( 419 'attachment_id' => $attachment_id, 420 ), 421 array( 422 'attachment_id' => $attachment_id, 423 ), 424 ) ); 433 $widget->save_settings( 434 array( 435 array( 436 'attachment_id' => $attachment_id, 437 ), 438 array( 439 'attachment_id' => $attachment_id, 440 ), 441 ) 442 ); 425 443 $result = $widget->display_media_state( array(), get_post( $attachment_id ) ); 426 444 $this->assertEqualSets( array( sprintf( $widget->l10n['media_library_state_multi']['singular'], 2 ) ), $result ); … … 466 484 } 467 485 468 $attachment_id = self::factory()->attachment->create_object( array( 469 'file' => DIR_TESTDATA . '/images/canola.jpg', 470 'post_parent' => 0, 471 'post_mime_type' => 'image/jpeg', 472 ) ); 486 $attachment_id = self::factory()->attachment->create_object( 487 array( 488 'file' => DIR_TESTDATA . '/images/canola.jpg', 489 'post_parent' => 0, 490 'post_mime_type' => 'image/jpeg', 491 ) 492 ); 473 493 474 494 $wp_widget_media = new ReflectionClass( 'WP_Widget_Media' ); 475 $has_content = $wp_widget_media->getMethod( 'has_content' );495 $has_content = $wp_widget_media->getMethod( 'has_content' ); 476 496 $has_content->setAccessible( true ); 477 497 478 $result = $has_content->invokeArgs( $this->get_mocked_class_instance(), array( 479 array( 480 'attachment_id' => 0, 481 'url' => '', 482 ), 483 ) ); 498 $result = $has_content->invokeArgs( 499 $this->get_mocked_class_instance(), array( 500 array( 501 'attachment_id' => 0, 502 'url' => '', 503 ), 504 ) 505 ); 484 506 $this->assertFalse( $result ); 485 507 486 $result = $has_content->invokeArgs( $this->get_mocked_class_instance(), array( 487 array( 488 'attachment_id' => $attachment_id, 489 'url' => '', 490 ), 491 ) ); 508 $result = $has_content->invokeArgs( 509 $this->get_mocked_class_instance(), array( 510 array( 511 'attachment_id' => $attachment_id, 512 'url' => '', 513 ), 514 ) 515 ); 492 516 $this->assertTrue( $result ); 493 517 494 $result = $has_content->invokeArgs( $this->get_mocked_class_instance(), array( 495 array( 496 'attachment_id' => 0, 497 'url' => 'http://example.com/image.jpg', 498 ), 499 ) ); 518 $result = $has_content->invokeArgs( 519 $this->get_mocked_class_instance(), array( 520 array( 521 'attachment_id' => 0, 522 'url' => 'http://example.com/image.jpg', 523 ), 524 ) 525 ); 500 526 $this->assertTrue( $result ); 501 527 }
Note: See TracChangeset
for help on using the changeset viewer.