Make WordPress Core


Ignore:
Timestamp:
11/25/2020 04:49:04 AM (4 years ago)
Author:
peterwilsoncc
Message:

Build/Test Tools: Use dataProviders for some kses tests.

Refactor several kses tests to use dataProviers rather than looping through assertions.

See #51802.

File:
1 edited

Legend:

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

    r48937 r49697  
    99
    1010    /**
     11     * @dataProvider data_wp_filter_post_kses_address
    1112     * @ticket 20210
    12      */
    13     function test_wp_filter_post_kses_address() {
     13     *
     14     * @param string $string        Test string for kses.
     15     * @param string $expect_string Expected result after passing through kses.
     16     */
     17    function test_wp_filter_post_kses_address( $string, $expect_string ) {
    1418        global $allowedposttags;
    1519
     20        $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     21    }
     22
     23    /**
     24     * Data provider for test_wp_filter_post_kses_address.
     25     *
     26     * @return array[] Arguments {
     27     *     @type string $string        Test string for kses.
     28     *     @type string $expect_string Expected result after passing through kses.
     29     * }
     30     */
     31    function data_wp_filter_post_kses_address() {
    1632        $attributes = array(
    1733            'class' => 'classname',
     
    2642        );
    2743
     44        $data = array();
     45
    2846        foreach ( $attributes as $name => $values ) {
    2947            foreach ( (array) $values as $value ) {
    3048                $string        = "<address $name='$value'>1 WordPress Avenue, The Internet.</address>";
    3149                $expect_string = "<address $name='" . str_replace( '; ', ';', trim( $value, ';' ) ) . "'>1 WordPress Avenue, The Internet.</address>";
    32                 $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     50
     51                $data[] = array( $string, $expect_string );
    3352            }
    3453        }
    35     }
    36 
    37     /**
     54
     55        return $data;
     56    }
     57
     58    /**
     59     * @dataProvider data_wp_filter_post_kses_a
    3860     * @ticket 20210
    39      */
    40     function test_wp_filter_post_kses_a() {
     61     *
     62     * @param string $string        Test string for kses.
     63     * @param string $expect_string Expected result after passing through kses.
     64     * @return void
     65     */
     66    function test_wp_filter_post_kses_a( $string, $expect_string ) {
    4167        global $allowedposttags;
    4268
     69        $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     70    }
     71
     72    /**
     73     * Data provider for test_wp_filter_post_kses_a.
     74     *
     75     * @return array[] Arguments {
     76     *     @type string $string        Test string for kses.
     77     *     @type string $expect_string Expected result after passing through kses.
     78     * }
     79     */
     80    function data_wp_filter_post_kses_a() {
    4381        $attributes = array(
    4482            'class'    => 'classname',
     
    5492        );
    5593
     94        $data = array();
     95
    5696        foreach ( $attributes as $name => $value ) {
    5797            if ( $value ) {
     
    64104            $string        = "<a $attr>I link this</a>";
    65105            $expect_string = "<a $expected_attr>I link this</a>";
    66             $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     106            $data[]        = array( $string, $expect_string );
    67107        }
     108
     109        return $data;
    68110    }
    69111
     
    123165
    124166    /**
     167     * @dataProvider data_wp_filter_post_kses_abbr
    125168     * @ticket 20210
    126      */
    127     function test_wp_filter_post_kses_abbr() {
     169     *
     170     * @param string $string        Test string for kses.
     171     * @param string $expect_string Expected result after passing through kses.
     172     * @return void
     173     */
     174    function test_wp_filter_post_kses_abbr( $string, $expect_string ) {
    128175        global $allowedposttags;
    129176
     177        $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     178    }
     179
     180    /**
     181     * Data provider for data_wp_filter_post_kses_abbr.
     182     *
     183     * @return array[] Arguments {
     184     *     @type string $string        Test string for kses.
     185     *     @type string $expect_string Expected result after passing through kses.
     186     * }
     187     */
     188    function data_wp_filter_post_kses_abbr() {
    130189        $attributes = array(
    131190            'class' => 'classname',
     
    135194        );
    136195
     196        $data = array();
     197
    137198        foreach ( $attributes as $name => $value ) {
    138199            $string        = "<abbr $name='$value'>WP</abbr>";
    139200            $expect_string = "<abbr $name='" . trim( $value, ';' ) . "'>WP</abbr>";
    140             $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     201            $data[]        = array( $string, $expect_string );
    141202        }
     203
     204        return $data;
    142205    }
    143206
Note: See TracChangeset for help on using the changeset viewer.