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. git-svn-id: https://develop.svn.wordpress.org/trunk@45101 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f4e57f92e4
commit
ffbc0e3b4e
@ -50,6 +50,39 @@ class Test_WP_Widget_Media_Audio extends WP_UnitTestCase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test get_instance_schema filtering.
|
||||||
|
*
|
||||||
|
* @covers WP_Widget_Media_Audio::get_instance_schema
|
||||||
|
*
|
||||||
|
* @ticket 45029
|
||||||
|
*/
|
||||||
|
function test_get_instance_schema_filtering() {
|
||||||
|
$wp_widget_audio = new WP_Widget_Media_Audio();
|
||||||
|
$schema = $wp_widget_audio->get_instance_schema();
|
||||||
|
|
||||||
|
add_filter( 'widget_media_audio_instance_schema', array( $this, 'filter_instance_schema' ), 10, 2 );
|
||||||
|
$schema = $wp_widget_audio->get_instance_schema();
|
||||||
|
|
||||||
|
$this->assertTrue( $schema['loop']['default'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters instance schema.
|
||||||
|
*
|
||||||
|
* @since 5.2.0
|
||||||
|
*
|
||||||
|
* @param array $schema Schema.
|
||||||
|
* @param WP_Widget_Media_Audio $widget Widget.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function filter_instance_schema( $schema, $widget ) {
|
||||||
|
// Override the default loop value (false).
|
||||||
|
$schema['loop']['default'] = true;
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test constructor.
|
* Test constructor.
|
||||||
*
|
*
|
||||||
|
@ -34,7 +34,6 @@ class Test_WP_Widget_Media_Image extends WP_UnitTestCase {
|
|||||||
function test_get_instance_schema() {
|
function test_get_instance_schema() {
|
||||||
$widget = new WP_Widget_Media_Image();
|
$widget = new WP_Widget_Media_Image();
|
||||||
$schema = $widget->get_instance_schema();
|
$schema = $widget->get_instance_schema();
|
||||||
|
|
||||||
$this->assertEqualSets(
|
$this->assertEqualSets(
|
||||||
array(
|
array(
|
||||||
'alt',
|
'alt',
|
||||||
@ -57,6 +56,39 @@ class Test_WP_Widget_Media_Image extends WP_UnitTestCase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test schema filtering.
|
||||||
|
*
|
||||||
|
* @covers WP_Widget_Media_Image::get_instance_schema
|
||||||
|
*
|
||||||
|
* @ticket 45029
|
||||||
|
*/
|
||||||
|
function test_get_instance_schema_filtering() {
|
||||||
|
$widget = new WP_Widget_Media_Image();
|
||||||
|
$schema = $widget->get_instance_schema();
|
||||||
|
|
||||||
|
add_filter( 'widget_media_image_instance_schema', array( $this, 'filter_instance_schema' ), 10, 2 );
|
||||||
|
$schema = $widget->get_instance_schema();
|
||||||
|
|
||||||
|
$this->assertSame( 'large', $schema['size']['default'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters instance schema.
|
||||||
|
*
|
||||||
|
* @since 5.2.0
|
||||||
|
*
|
||||||
|
* @param array $schema Schema.
|
||||||
|
* @param WP_Widget_Media_Image $widget Widget.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function filter_instance_schema( $schema, $widget ) {
|
||||||
|
// Override the default size value ('medium').
|
||||||
|
$schema['size']['default'] = 'large';
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test constructor.
|
* Test constructor.
|
||||||
*
|
*
|
||||||
|
@ -51,6 +51,39 @@ class Test_WP_Widget_Media_Video extends WP_UnitTestCase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test schema filtering.
|
||||||
|
*
|
||||||
|
* @covers WP_Widget_Media_Video::get_instance_schema
|
||||||
|
*
|
||||||
|
* @ticket 45029
|
||||||
|
*/
|
||||||
|
function test_get_instance_schema_filtering() {
|
||||||
|
$widget = new WP_Widget_Media_Video();
|
||||||
|
$schema = $widget->get_instance_schema();
|
||||||
|
|
||||||
|
add_filter( 'widget_media_video_instance_schema', array( $this, 'filter_instance_schema' ), 10, 2 );
|
||||||
|
$schema = $widget->get_instance_schema();
|
||||||
|
|
||||||
|
$this->assertTrue( $schema['loop']['default'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters instance schema.
|
||||||
|
*
|
||||||
|
* @since 5.2.0
|
||||||
|
*
|
||||||
|
* @param array $schema Schema.
|
||||||
|
* @param WP_Widget_Media_Video $widget Widget.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function filter_instance_schema( $schema, $widget ) {
|
||||||
|
// Override the default loop value (false).
|
||||||
|
$schema['loop']['default'] = true;
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test constructor.
|
* Test constructor.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user