Skip to content

Commit c1c9c08

Browse files
committed
Testing 52728 / debugging the test
1 parent e7ac821 commit c1c9c08

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/wp-includes/class-wp-widget.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ public function display_callback( $args, $widget_args = 1 ) {
366366
$instances = $this->get_settings();
367367

368368
if ( array_key_exists( $this->number, $instances ) ) {
369+
// if ( isset( $instances[ $this->number ] ) ) {
369370
$instance = $instances[ $this->number ];
370371

371372
/**

tests/phpunit/tests/widgets.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,88 @@ function test_wp_widget__register() {
590590

591591
// @todo Test WP_Widget::display_callback().
592592

593+
/**
594+
* @ticket 52728
595+
*/
596+
function test_widget_display_callback_handles_arrayobject() {
597+
$widget = new WP_Widget_Text();
598+
599+
register_widget( $widget );
600+
/*
601+
update_option(
602+
$widget->option_name,
603+
new ArrayObject(
604+
array(
605+
2 => array( 'title' => 'Test Title' ),
606+
'_multiwidget' => 1,
607+
'__i__' => true,
608+
)
609+
)
610+
);
611+
*/
612+
// $this->expectOutputString( 'Test Title' );
613+
614+
ob_start();
615+
$widget->widget(
616+
array(
617+
'before_widget' => '<section>',
618+
'after_widget' => "</section>\n",
619+
'before_title' => '<h2>',
620+
'after_title' => "</h2>\n",
621+
),
622+
new ArrayObject(
623+
array(
624+
2 => array( 'title' => 'Test Title' ),
625+
'_multiwidget' => 1,
626+
'__i__' => true,
627+
)
628+
)
629+
);
630+
/*
631+
the_widget(
632+
'WP_Widget_Text',
633+
get_option( $widget->option_name ),
634+
array(
635+
'before_widget' => '<section>',
636+
'after_widget' => "</section>\n",
637+
'before_title' => '<h2>',
638+
'after_title' => "</h2>\n",
639+
)
640+
);
641+
*/
642+
$widget_content = ob_get_clean();
643+
// unregister_widget( 'WP_Widget_Text' );
644+
645+
646+
var_dump($widget_content);
647+
unregister_widget( $widget );
648+
649+
// $this->assertContains( 'Test Title', $actual );
650+
}
651+
652+
/*
653+
wp_widgets_init();
654+
$wp_widget_search = $wp_registered_widgets['search-2']['callback'][0];
655+
656+
$settings = $wp_widget_search->get_settings();
657+
$overridden_title = 'Unit Tested';
658+
659+
/*
660+
* Note that if a plugin is filtering $settings to be an ArrayIterator,
661+
* then doing this:
662+
* $settings[2]['title'] = $overridden_title;
663+
* Will fail with this:
664+
* > Indirect modification of overloaded element of X has no effect.
665+
* So this is why the value must be obtained.
666+
* /
667+
$instance = $settings[2];
668+
$instance['title'] = $overridden_title;
669+
$settings[2] = $instance;
670+
671+
$wp_widget_search->save_settings( $settings );
672+
673+
$option_value = get_option( $wp_widget_search->option_name );
674+
*/
593675
/**
594676
* @see WP_Widget::is_preview()
595677
*/

0 commit comments

Comments
 (0)