Widgets: Create WP_Widget_Mock
as a mock of WP_Widget
which can be used for widget tests.
You cannot instantiate an abstract class. Not even in WordPress world. See #35981. git-svn-id: https://develop.svn.wordpress.org/trunk@37427 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c1ec341ddb
commit
e2329076f3
@ -336,7 +336,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
* @see WP_Widget::form()
|
||||
*/
|
||||
function test_wp_widget_form() {
|
||||
$widget = new WP_Widget( 'foo', 'Foo' );
|
||||
$widget = new WP_Widget_Mock( 'foo', 'Foo' );
|
||||
ob_start();
|
||||
$retval = $widget->form( array() );
|
||||
$output = ob_get_clean();
|
||||
@ -350,7 +350,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
function test_wp_widget_constructor() {
|
||||
$id_base = 'foo';
|
||||
$name = 'Foo';
|
||||
$foo_widget = new WP_Widget( $id_base, $name );
|
||||
$foo_widget = new WP_Widget_Mock( $id_base, $name );
|
||||
|
||||
$this->assertEquals( $id_base, $foo_widget->id_base );
|
||||
$this->assertEquals( $name, $foo_widget->name );
|
||||
@ -368,7 +368,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
$control_options = array(
|
||||
'id_base' => 'bar_id_base',
|
||||
);
|
||||
$bar_widget = new WP_Widget( $id_base, $name, $widget_options, $control_options );
|
||||
$bar_widget = new WP_Widget_Mock( $id_base, $name, $widget_options, $control_options );
|
||||
$this->assertEquals( $widget_options['classname'], $bar_widget->widget_options['classname'] );
|
||||
$this->assertEquals( $control_options['id_base'], $bar_widget->control_options['id_base'] );
|
||||
}
|
||||
@ -379,7 +379,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
*
|
||||
*/
|
||||
function test_wp_widget_get_field_name( $expected, $value_to_test ) {
|
||||
$widget = new WP_Widget( 'foo', 'Foo' );
|
||||
$widget = new WP_Widget_Mock( 'foo', 'Foo' );
|
||||
$widget->_set( 2 );
|
||||
$this->assertEquals( $expected, $widget->get_field_name( $value_to_test ) );
|
||||
}
|
||||
@ -430,7 +430,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
*
|
||||
*/
|
||||
function test_wp_widget_get_field_id( $expected, $value_to_test ) {
|
||||
$widget = new WP_Widget( 'foo', 'Foo' );
|
||||
$widget = new WP_Widget_Mock( 'foo', 'Foo' );
|
||||
$widget->_set( 2 );
|
||||
$this->assertEquals( $expected, $widget->get_field_id( $value_to_test ) );
|
||||
}
|
||||
@ -503,7 +503,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
function test_wp_widget_is_preview() {
|
||||
global $wp_customize;
|
||||
|
||||
$widget = new WP_Widget( 'foo', 'Foo' );
|
||||
$widget = new WP_Widget_Mock( 'foo', 'Foo' );
|
||||
|
||||
$this->assertEmpty( $wp_customize );
|
||||
$this->assertFalse( $widget->is_preview() );
|
||||
@ -679,3 +679,14 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock of WP_Widget.
|
||||
*
|
||||
* @since 4.6.0
|
||||
*/
|
||||
class WP_Widget_Mock extends WP_Widget {
|
||||
public function widget( $args, $instance ) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user