Make WordPress Core

Ticket #40772: 40772.1.diff

File 40772.1.diff, 5.1 KB (added by westonruter, 8 years ago)

Add unit tests

  • src/wp-includes/widgets/class-wp-widget-text.php

    diff --git src/wp-includes/widgets/class-wp-widget-text.php src/wp-includes/widgets/class-wp-widget-text.php
    index 434a123f90..b3ffd90b18 100644
    class WP_Widget_Text extends WP_Widget { 
    6767                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
    6868                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
    6969
    70                 $widget_text = ! empty( $instance['text'] ) ? $instance['text'] : '';
     70                $text = ! empty( $instance['text'] ) ? $instance['text'] : '';
    7171
    7272                /**
    7373                 * Filters the content of the Text widget.
    class WP_Widget_Text extends WP_Widget { 
    7575                 * @since 2.3.0
    7676                 * @since 4.4.0 Added the `$this` parameter.
    7777                 *
    78                  * @param string         $widget_text The widget content.
    79                  * @param array          $instance    Array of settings for the current widget.
    80                  * @param WP_Widget_Text $this        Current Text widget instance.
     78                 * @param string         $text    The widget content.
     79                 * @param array          $instance Array of settings for the current widget.
     80                 * @param WP_Widget_Text $this     Current Text widget instance.
    8181                 */
    82                 $text = apply_filters( 'widget_text', $widget_text, $instance, $this );
     82                $text = apply_filters( 'widget_text', $text, $instance, $this );
    8383
    8484                if ( isset( $instance['filter'] ) ) {
    8585                        if ( 'content' === $instance['filter'] ) {
    class WP_Widget_Text extends WP_Widget { 
    9191                                 *
    9292                                 * @since 4.8.0
    9393                                 *
    94                                  * @param string         $widget_text The widget content.
    95                                  * @param array          $instance    Array of settings for the current widget.
    96                                  * @param WP_Widget_Text $this        Current Text widget instance.
     94                                 * @param string         $text    The widget content.
     95                                 * @param array          $instance Array of settings for the current widget.
     96                                 * @param WP_Widget_Text $this     Current Text widget instance.
    9797                                 */
    98                                 $text = apply_filters( 'widget_text_content', $widget_text, $instance, $this );
     98                                $text = apply_filters( 'widget_text_content', $text, $instance, $this );
    9999
    100100                        } elseif ( $instance['filter'] ) {
    101101                                $text = wpautop( $text ); // Back-compat for instances prior to 4.8.
  • tests/phpunit/tests/widgets/text-widget.php

    diff --git tests/phpunit/tests/widgets/text-widget.php tests/phpunit/tests/widgets/text-widget.php
    index 81419051b6..a28e6a668a 100644
    class Test_WP_Widget_Text extends WP_UnitTestCase { 
    7474                        'filter' => false,
    7575                );
    7676
    77                 add_filter( 'widget_text_content', array( $this, 'filter_widget_text_content' ), 10, 3 );
    78                 add_filter( 'widget_text', array( $this, 'filter_widget_text' ), 10, 3 );
     77                add_filter( 'widget_text_content', array( $this, 'filter_widget_text_content' ), 5, 3 );
     78                add_filter( 'widget_text', array( $this, 'filter_widget_text' ), 5, 3 );
    7979
    8080                // Test with filter=false.
    8181                ob_start();
    class Test_WP_Widget_Text extends WP_UnitTestCase { 
    8585                $this->assertNotContains( '<br />', $output );
    8686                $this->assertEmpty( $this->widget_text_content_args );
    8787                $this->assertNotEmpty( $this->widget_text_args );
     88                $this->assertContains( '[filter:widget_text]', $output );
     89                $this->assertNotContains( '[filter:widget_text_content]', $output );
    8890
    8991                // Test with filter=true.
    9092                $instance['filter'] = true;
    class Test_WP_Widget_Text extends WP_UnitTestCase { 
    98100                $this->assertEquals( $instance, $this->widget_text_args[1] );
    99101                $this->assertEquals( $widget, $this->widget_text_args[2] );
    100102                $this->assertEmpty( $this->widget_text_content_args );
     103                $this->assertContains( '[filter:widget_text]', $output );
     104                $this->assertNotContains( '[filter:widget_text_content]', $output );
    101105
    102106                // Test with filter=content, the upgraded widget.
    103107                $instance['filter'] = 'content';
    class Test_WP_Widget_Text extends WP_UnitTestCase { 
    111115                $this->assertEquals( $instance, $this->widget_text_args[1] );
    112116                $this->assertEquals( $widget, $this->widget_text_args[2] );
    113117                $this->assertCount( 3, $this->widget_text_content_args );
    114                 $this->assertEquals( wpautop( $instance['text'] ), $this->widget_text_content_args[0] );
     118                $this->assertEquals( $instance['text'] . '[filter:widget_text]', $this->widget_text_content_args[0] );
    115119                $this->assertEquals( $instance, $this->widget_text_content_args[1] );
    116120                $this->assertEquals( $widget, $this->widget_text_content_args[2] );
     121                $this->assertContains( wpautop( $instance['text'] . '[filter:widget_text][filter:widget_text_content]' ), $output );
    117122        }
    118123
    119124        /**
    class Test_WP_Widget_Text extends WP_UnitTestCase { 
    127132        function filter_widget_text( $widget_text, $instance, $widget ) {
    128133                $this->widget_text_args = func_get_args();
    129134
     135                $widget_text .= '[filter:widget_text]';
    130136                return $widget_text;
    131137        }
    132138
    class Test_WP_Widget_Text extends WP_UnitTestCase { 
    141147        function filter_widget_text_content( $widget_text, $instance, $widget ) {
    142148                $this->widget_text_content_args = func_get_args();
    143149
     150                $widget_text .= '[filter:widget_text_content]';
    144151                return $widget_text;
    145152        }
    146153