Make WordPress Core


Ignore:
Timestamp:
06/23/2022 02:24:08 PM (4 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/attachment/slashes.php

    r52010 r53557  
    77 */
    88class Tests_Attachment_Slashes extends WP_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         // It is important to test with both even and odd numbered slashes,
    21         // as KSES does a strip-then-add slashes in some of its function calls.
    22         $this->slash_1 = 'String with 1 slash \\';
    23         $this->slash_2 = 'String with 2 slashes \\\\';
    24         $this->slash_3 = 'String with 3 slashes \\\\\\';
    25         $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    26         $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    27         $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    28         $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    2933    }
    3034
     
    3640            array(
    3741                'post_status'           => 'publish',
    38                 'post_title'            => $this->slash_1,
    39                 'post_content_filtered' => $this->slash_3,
    40                 'post_excerpt'          => $this->slash_5,
     42                'post_title'            => self::SLASH_1,
     43                'post_content_filtered' => self::SLASH_3,
     44                'post_excerpt'          => self::SLASH_5,
    4145                'post_type'             => 'post',
    4246            )
     
    4448        $post    = get_post( $post_id );
    4549
    46         $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
    47         $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content_filtered );
    48         $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );
     50        $this->assertSame( wp_unslash( self::SLASH_1 ), $post->post_title );
     51        $this->assertSame( wp_unslash( self::SLASH_3 ), $post->post_content_filtered );
     52        $this->assertSame( wp_unslash( self::SLASH_5 ), $post->post_excerpt );
    4953
    5054        $post_id = wp_insert_attachment(
    5155            array(
    5256                'post_status'           => 'publish',
    53                 'post_title'            => $this->slash_2,
    54                 'post_content_filtered' => $this->slash_4,
    55                 'post_excerpt'          => $this->slash_6,
     57                'post_title'            => self::SLASH_2,
     58                'post_content_filtered' => self::SLASH_4,
     59                'post_excerpt'          => self::SLASH_6,
    5660                'post_type'             => 'post',
    5761            )
     
    5963        $post    = get_post( $post_id );
    6064
    61         $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
    62         $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content_filtered );
    63         $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );
     65        $this->assertSame( wp_unslash( self::SLASH_2 ), $post->post_title );
     66        $this->assertSame( wp_unslash( self::SLASH_4 ), $post->post_content_filtered );
     67        $this->assertSame( wp_unslash( self::SLASH_6 ), $post->post_excerpt );
    6468    }
    6569
Note: See TracChangeset for help on using the changeset viewer.