Make WordPress Core

Ticket #52728: 52728.2.diff

File 52728.2.diff, 1.5 KB (added by dlh, 5 years ago)
  • src/wp-includes/class-wp-widget.php

    diff --git src/wp-includes/class-wp-widget.php src/wp-includes/class-wp-widget.php
    index 71381d35e6..8be19f7fef 100644
    class WP_Widget { 
    358358                $this->_set( $widget_args['number'] );
    359359                $instances = $this->get_settings();
    360360
    361                 if ( array_key_exists( $this->number, $instances ) ) {
     361                if ( isset( $instances[ $this->number ] ) ) {
    362362                        $instance = $instances[ $this->number ];
    363363
    364364                        /**
  • tests/phpunit/tests/widgets.php

    diff --git tests/phpunit/tests/widgets.php tests/phpunit/tests/widgets.php
    index 4c34dfcd73..136422e9de 100644
    class Tests_Widgets extends WP_UnitTestCase { 
    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                ob_start();
     613                $widget->display_callback(
     614                        array(
     615                                'before_widget' => '<section>',
     616                                'after_widget'  => "</section>\n",
     617                                'before_title'  => '<h2>',
     618                                'after_title'   => "</h2>\n",
     619                        ),
     620                        2
     621                );
     622                $actual = ob_get_clean();
     623
     624                unregister_widget( $widget );
     625
     626                $this->assertContains( 'Test Title', $actual );
     627        }
     628
    593629        /**
    594630         * @see WP_Widget::is_preview()
    595631         */