Make WordPress Core

Changeset 45101


Ignore:
Timestamp:
04/02/2019 10:14:19 PM (5 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.

Location:
trunk/tests/phpunit/tests/widgets
Files:
3 edited

Legend:

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

    r43571 r45101  
    5252
    5353    /**
     54     * Test get_instance_schema filtering.
     55     *
     56     * @covers WP_Widget_Media_Audio::get_instance_schema
     57     *
     58     * @ticket 45029
     59     */
     60    function test_get_instance_schema_filtering() {
     61        $wp_widget_audio = new WP_Widget_Media_Audio();
     62        $schema          = $wp_widget_audio->get_instance_schema();
     63
     64        add_filter( 'widget_media_audio_instance_schema', array( $this, 'filter_instance_schema' ), 10, 2 );
     65        $schema = $wp_widget_audio->get_instance_schema();
     66
     67        $this->assertTrue( $schema['loop']['default'] );
     68    }
     69
     70    /**
     71     * Filters instance schema.
     72     *
     73     * @since 5.2.0
     74     *
     75     * @param array                 $schema Schema.
     76     * @param WP_Widget_Media_Audio $widget Widget.
     77     *
     78     * @return array
     79     */
     80    public function filter_instance_schema( $schema, $widget ) {
     81        // Override the default loop value (false).
     82        $schema['loop']['default'] = true;
     83        return $schema;
     84    }
     85
     86    /**
    5487     * Test constructor.
    5588     *
  • trunk/tests/phpunit/tests/widgets/media-image-widget.php

    r43571 r45101  
    3535        $widget = new WP_Widget_Media_Image();
    3636        $schema = $widget->get_instance_schema();
    37 
    3837        $this->assertEqualSets(
    3938            array(
     
    5958
    6059    /**
     60     * Test schema filtering.
     61     *
     62     * @covers WP_Widget_Media_Image::get_instance_schema
     63     *
     64     * @ticket 45029
     65     */
     66    function test_get_instance_schema_filtering() {
     67        $widget = new WP_Widget_Media_Image();
     68        $schema = $widget->get_instance_schema();
     69
     70        add_filter( 'widget_media_image_instance_schema', array( $this, 'filter_instance_schema' ), 10, 2 );
     71        $schema = $widget->get_instance_schema();
     72
     73        $this->assertSame( 'large', $schema['size']['default'] );
     74    }
     75
     76    /**
     77     * Filters instance schema.
     78     *
     79     * @since 5.2.0
     80     *
     81     * @param array                 $schema Schema.
     82     * @param WP_Widget_Media_Image $widget Widget.
     83     *
     84     * @return array
     85     */
     86    public function filter_instance_schema( $schema, $widget ) {
     87        // Override the default size value ('medium').
     88        $schema['size']['default'] = 'large';
     89        return $schema;
     90    }
     91
     92    /**
    6193     * Test constructor.
    6294     *
  • 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.