WordPress.org

Make WordPress Core

Changeset 37427


Ignore:
Timestamp:
05/12/2016 09:24:18 PM (4 years ago)
Author:
ocean90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets.php

    r37344 r37427  
    337337     */
    338338    function test_wp_widget_form() {
    339         $widget = new WP_Widget( 'foo', 'Foo' );
     339        $widget = new WP_Widget_Mock( 'foo', 'Foo' );
    340340        ob_start();
    341341        $retval = $widget->form( array() );
     
    351351        $id_base = 'foo';
    352352        $name = 'Foo';
    353         $foo_widget = new WP_Widget( $id_base, $name );
     353        $foo_widget = new WP_Widget_Mock( $id_base, $name );
    354354
    355355        $this->assertEquals( $id_base, $foo_widget->id_base );
     
    369369            'id_base' => 'bar_id_base',
    370370        );
    371         $bar_widget = new WP_Widget( $id_base, $name, $widget_options, $control_options );
     371        $bar_widget = new WP_Widget_Mock( $id_base, $name, $widget_options, $control_options );
    372372        $this->assertEquals( $widget_options['classname'], $bar_widget->widget_options['classname'] );
    373373        $this->assertEquals( $control_options['id_base'], $bar_widget->control_options['id_base'] );
     
    380380     */
    381381    function test_wp_widget_get_field_name( $expected, $value_to_test ) {
    382         $widget = new WP_Widget( 'foo', 'Foo' );
     382        $widget = new WP_Widget_Mock( 'foo', 'Foo' );
    383383        $widget->_set( 2 );
    384384        $this->assertEquals( $expected, $widget->get_field_name( $value_to_test ) );
     
    431431     */
    432432    function test_wp_widget_get_field_id( $expected, $value_to_test ) {
    433         $widget = new WP_Widget( 'foo', 'Foo' );
     433        $widget = new WP_Widget_Mock( 'foo', 'Foo' );
    434434        $widget->_set( 2 );
    435435        $this->assertEquals( $expected, $widget->get_field_id( $value_to_test ) );
     
    504504        global $wp_customize;
    505505
    506         $widget = new WP_Widget( 'foo', 'Foo' );
     506        $widget = new WP_Widget_Mock( 'foo', 'Foo' );
    507507
    508508        $this->assertEmpty( $wp_customize );
     
    680680
    681681}
     682
     683/**
     684 * Mock of WP_Widget.
     685 *
     686 * @since 4.6.0
     687 */
     688class WP_Widget_Mock extends WP_Widget {
     689    public function widget( $args, $instance ) {
     690        return;
     691    }
     692};
Note: See TracChangeset for help on using the changeset viewer.