Make WordPress Core


Ignore:
Timestamp:
06/23/2022 02:24:08 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Remove dynamic properties in Tests_*_Slashes.

Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

In this particular case, the test classes contain a set_up() method that sets a group of properties, which are used by the tests, but the values of these properties are never changed by the tests.

In other words, setting these properties in the set_up() is an unnecessary overhead and the properties should be changed to class constants.

Follow-up to [1041/tests], [1071/tests].

Props jrf.
See #56033.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/slashes.php

    r52010 r53557  
    77 */
    88class Tests_Term_Slashes extends WP_Ajax_UnitTestCase {
     9
     10    /*
     11     * It is important to test with both even and odd numbered slashes,
     12     * as KSES does a strip-then-add slashes in some of its function calls.
     13     */
     14
     15    const SLASH_1 = 'String with 1 slash \\';
     16    const SLASH_2 = 'String with 2 slashes \\\\';
     17    const SLASH_3 = 'String with 3 slashes \\\\\\';
     18    const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19    const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20    const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21    const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
     22
    923    protected static $author_id;
    1024
     
    1731
    1832        wp_set_current_user( self::$author_id );
    19 
    20         $this->slash_1 = 'String with 1 slash \\';
    21         $this->slash_2 = 'String with 2 slashes \\\\';
    22         $this->slash_3 = 'String with 3 slashes \\\\\\';
    23         $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    24         $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    25         $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    26         $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    2733    }
    2834
     
    3743        foreach ( $taxonomies as $taxonomy ) {
    3844            $insert = wp_insert_term(
    39                 $this->slash_1,
     45                self::SLASH_1,
    4046                $taxonomy,
    4147                array(
    4248                    'slug'        => 'slash_test_1_' . $taxonomy,
    43                     'description' => $this->slash_3,
     49                    'description' => self::SLASH_3,
    4450                )
    4551            );
    4652            $term   = get_term( $insert['term_id'], $taxonomy );
    47             $this->assertSame( wp_unslash( $this->slash_1 ), $term->name );
    48             $this->assertSame( wp_unslash( $this->slash_3 ), $term->description );
     53            $this->assertSame( wp_unslash( self::SLASH_1 ), $term->name );
     54            $this->assertSame( wp_unslash( self::SLASH_3 ), $term->description );
    4955
    5056            $insert = wp_insert_term(
    51                 $this->slash_3,
     57                self::SLASH_3,
    5258                $taxonomy,
    5359                array(
    5460                    'slug'        => 'slash_test_2_' . $taxonomy,
    55                     'description' => $this->slash_5,
     61                    'description' => self::SLASH_5,
    5662                )
    5763            );
    5864            $term   = get_term( $insert['term_id'], $taxonomy );
    59             $this->assertSame( wp_unslash( $this->slash_3 ), $term->name );
    60             $this->assertSame( wp_unslash( $this->slash_5 ), $term->description );
     65            $this->assertSame( wp_unslash( self::SLASH_3 ), $term->name );
     66            $this->assertSame( wp_unslash( self::SLASH_5 ), $term->description );
    6167
    6268            $insert = wp_insert_term(
    63                 $this->slash_2,
     69                self::SLASH_2,
    6470                $taxonomy,
    6571                array(
    6672                    'slug'        => 'slash_test_3_' . $taxonomy,
    67                     'description' => $this->slash_4,
     73                    'description' => self::SLASH_4,
    6874                )
    6975            );
    7076            $term   = get_term( $insert['term_id'], $taxonomy );
    71             $this->assertSame( wp_unslash( $this->slash_2 ), $term->name );
    72             $this->assertSame( wp_unslash( $this->slash_4 ), $term->description );
     77            $this->assertSame( wp_unslash( self::SLASH_2 ), $term->name );
     78            $this->assertSame( wp_unslash( self::SLASH_4 ), $term->description );
    7379        }
    7480    }
     
    9399                $taxonomy,
    94100                array(
    95                     'name'        => $this->slash_1,
    96                     'description' => $this->slash_3,
     101                    'name'        => self::SLASH_1,
     102                    'description' => self::SLASH_3,
    97103                )
    98104            );
    99105
    100106            $term = get_term( $term_id, $taxonomy );
    101             $this->assertSame( wp_unslash( $this->slash_1 ), $term->name );
    102             $this->assertSame( wp_unslash( $this->slash_3 ), $term->description );
     107            $this->assertSame( wp_unslash( self::SLASH_1 ), $term->name );
     108            $this->assertSame( wp_unslash( self::SLASH_3 ), $term->description );
    103109
    104110            $update = wp_update_term(
     
    106112                $taxonomy,
    107113                array(
    108                     'name'        => $this->slash_3,
    109                     'description' => $this->slash_5,
     114                    'name'        => self::SLASH_3,
     115                    'description' => self::SLASH_5,
    110116                )
    111117            );
    112118            $term   = get_term( $term_id, $taxonomy );
    113             $this->assertSame( wp_unslash( $this->slash_3 ), $term->name );
    114             $this->assertSame( wp_unslash( $this->slash_5 ), $term->description );
     119            $this->assertSame( wp_unslash( self::SLASH_3 ), $term->name );
     120            $this->assertSame( wp_unslash( self::SLASH_5 ), $term->description );
    115121
    116122            $update = wp_update_term(
     
    118124                $taxonomy,
    119125                array(
    120                     'name'        => $this->slash_2,
    121                     'description' => $this->slash_4,
     126                    'name'        => self::SLASH_2,
     127                    'description' => self::SLASH_4,
    122128                )
    123129            );
    124130            $term   = get_term( $term_id, $taxonomy );
    125             $this->assertSame( wp_unslash( $this->slash_2 ), $term->name );
    126             $this->assertSame( wp_unslash( $this->slash_4 ), $term->description );
     131            $this->assertSame( wp_unslash( self::SLASH_2 ), $term->name );
     132            $this->assertSame( wp_unslash( self::SLASH_4 ), $term->description );
    127133        }
    128134    }
Note: See TracChangeset for help on using the changeset viewer.