Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets/custom-html-widget.php

    r46586 r48937  
    4848    public function test_construct() {
    4949        $widget = new WP_Widget_Custom_HTML();
    50         $this->assertEquals( 'custom_html', $widget->id_base );
    51         $this->assertEquals( 'widget_custom_html', $widget->widget_options['classname'] );
    52         $this->assertEquals( 400, $widget->control_options['width'] );
    53         $this->assertEquals( 350, $widget->control_options['height'] );
     50        $this->assertSame( 'custom_html', $widget->id_base );
     51        $this->assertSame( 'widget_custom_html', $widget->widget_options['classname'] );
     52        $this->assertSame( 400, $widget->control_options['width'] );
     53        $this->assertSame( 350, $widget->control_options['height'] );
    5454        $this->assertTrue( $widget->widget_options['customize_selective_refresh'] );
    5555    }
     
    6565        $widget->_register();
    6666
    67         $this->assertEquals( 10, has_action( 'admin_print_scripts-widgets.php', array( $widget, 'enqueue_admin_scripts' ) ) );
    68         $this->assertEquals( 10, has_action( 'admin_footer-widgets.php', array( 'WP_Widget_Custom_HTML', 'render_control_template_scripts' ) ) );
    69         $this->assertEquals( 10, has_action( 'admin_head-widgets.php', array( 'WP_Widget_Custom_HTML', 'add_help_text' ) ) );
     67        $this->assertSame( 10, has_action( 'admin_print_scripts-widgets.php', array( $widget, 'enqueue_admin_scripts' ) ) );
     68        $this->assertSame( 10, has_action( 'admin_footer-widgets.php', array( 'WP_Widget_Custom_HTML', 'render_control_template_scripts' ) ) );
     69        $this->assertSame( 10, has_action( 'admin_head-widgets.php', array( 'WP_Widget_Custom_HTML', 'add_help_text' ) ) );
    7070        $this->assertContains( 'wp.customHtmlWidgets.idBases.push( "custom_html" );', wp_scripts()->registered['custom-html-widgets']->extra['after'] );
    7171    }
     
    118118        $this->assertNotContains( '<br>', $output );
    119119        $this->assertNotContains( '</u>', $output );
    120         $this->assertEquals( $text_widget_instance, $this->widget_text_args[1] );
    121         $this->assertEquals( $instance, $this->widget_custom_html_content_args[1] );
     120        $this->assertSame( $text_widget_instance, $this->widget_text_args[1] );
     121        $this->assertSame( $instance, $this->widget_custom_html_content_args[1] );
    122122        $this->assertSame( $widget, $this->widget_text_args[2] );
    123123        $this->assertSame( $widget, $this->widget_custom_html_content_args[2] );
     
    186186        );
    187187        $result   = $widget->update( $instance, array() );
    188         $this->assertEquals( $result, $expected );
     188        $this->assertSame( $result, $expected );
    189189
    190190        // Make sure KSES is applying as expected.
     
    194194        $expected['content'] = $instance['content'];
    195195        $result              = $widget->update( $instance, array() );
    196         $this->assertEquals( $result, $expected );
     196        $this->assertSame( $result, $expected );
    197197        remove_filter( 'map_meta_cap', array( $this, 'grant_unfiltered_html_cap' ) );
    198198
     
    202202        $expected['content'] = wp_kses_post( $instance['content'] );
    203203        $result              = $widget->update( $instance, array() );
    204         $this->assertEquals( $result, $expected );
     204        $this->assertSame( $result, $expected );
    205205        remove_filter( 'map_meta_cap', array( $this, 'revoke_unfiltered_html_cap' ), 10 );
    206206    }
Note: See TracChangeset for help on using the changeset viewer.