WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/02/2019 10:14:19 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Widgets: Make sure changes to media widgets' instance schema via widget_{$this->id_base}_instance_schema filter are not overridden by subclasses.

Add unit tests missed in [45100].

Props Toro_Unit, birgire.
See #45029.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets/media-video-widget.php

    r43571 r45101  
    5353
    5454    /**
     55     * Test schema filtering.
     56     *
     57     * @covers WP_Widget_Media_Video::get_instance_schema
     58     *
     59     * @ticket 45029
     60     */
     61    function test_get_instance_schema_filtering() {
     62        $widget = new WP_Widget_Media_Video();
     63        $schema = $widget->get_instance_schema();
     64
     65        add_filter( 'widget_media_video_instance_schema', array( $this, 'filter_instance_schema' ), 10, 2 );
     66        $schema = $widget->get_instance_schema();
     67
     68        $this->assertTrue( $schema['loop']['default'] );
     69    }
     70
     71    /**
     72     * Filters instance schema.
     73     *
     74     * @since 5.2.0
     75     *
     76     * @param array                 $schema Schema.
     77     * @param WP_Widget_Media_Video $widget Widget.
     78     *
     79     * @return array
     80     */
     81    public function filter_instance_schema( $schema, $widget ) {
     82        // Override the default loop value (false).
     83        $schema['loop']['default'] = true;
     84        return $schema;
     85    }
     86
     87    /**
    5588     * Test constructor.
    5689     *
Note: See TracChangeset for help on using the changeset viewer.