Make WordPress Core

Changeset 60446


Ignore:
Timestamp:
07/10/2025 04:00:44 PM (13 hours ago)
Author:
jonsurrell
Message:

Build/Test Tools: Expand and improve wp_kses_normalize_entities tests.

Update test to use a data provider for test cases.
Add a variety of HTML character references covering named, decimal, and hexadecimal forms.

Developed in https://github.com/WordPress/wordpress-develop/pull/9095.

Props jonsurrell, cbravobernal.
See #63167.

File:
1 edited

Legend:

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

    r60251 r60446  
    552552
    553553    /**
     554     * Data provider.
     555     */
     556    public static function data_normalize_entities(): array {
     557        return array(
     558            /**
     559             * These examples are from the wp_kses_normalize_entities function description.
     560             */
     561            'AT&T'                               => array( 'AT&T', 'AT&T' ),
     562            ':'                           => array( ':', ':' ),
     563            '&#XYZZY;'                           => array( '&#XYZZY;', '&#XYZZY;' ),
     564
     565            'Named ref &'                    => array( '♠', '♠' ),
     566            'Named ref &'                    => array( '♠', '♠' ),
     567            'Named ref ♠'                 => array( '♠', '♠' ),
     568            'Named ref ¹'                   => array( '¹', '¹' ),
     569            'Named ref ²'                   => array( '²', '²' ),
     570            'Named ref ³'                   => array( '³', '³' ),
     571            'Named ref ¼'                 => array( '¼', '¼' ),
     572            'Named ref ½'                 => array( '½', '½' ),
     573            'Named ref ¾'                 => array( '¾', '¾' ),
     574            'Named ref ∴'                 => array( '∴', '∴' ),
     575
     576            'Decimal ref 	 ( )'               => array( '	', '	' ),
     577            'Decimal ref " (")'              => array( '"', '"' ),
     578            'Decimal ref " (")'            => array( '"', '"' ),
     579            'Decimal ref & (&)'              => array( '&', '&' ),
     580            "Decimal ref ' (')"              => array( ''', ''' ),
     581            'Decimal ref 😍 (😍)'          => array( '😍', '😍' ),
     582            'Decimal ref 😍 (😍)'        => array( '😍', '😍' ),
     583
     584            'Hex ref 	 ( )'                  => array( '	', '	' ),
     585            'Hex ref " (")'                 => array( '"', '"' ),
     586            'Hex ref " (")'               => array( '"', '"' ),
     587            'Hex ref & (&)'                 => array( '&', '&' ),
     588            "Hex ref ' (')"                 => array( ''', ''' ),
     589            'Hex ref 😍 (😍)'              => array( '😍', '😍' ),
     590            'Hex ref 😍 (😍)'            => array( '😍', '😍' ),
     591
     592            'HEX REF " (")'                 => array( '"', '"' ),
     593            'HEX REF & (&)'                 => array( '&', '&' ),
     594            "HEX REF ' (')"                 => array( ''', ''' ),
     595            'HEX REF 😍 (😍)'              => array( '😍', '😍' ),
     596
     597            'Encoded named ref &'        => array( '&', '&' ),
     598            'Encoded named ref &'        => array( '&', '&' ),
     599            'Encoded named ref &'       => array( '&', '&' ),
     600
     601            /*
     602             * The codepoint value here is outside of the valid unicode range whose
     603             * maximum is 0x10FFFF or 1114111.
     604             */
     605            'Invalid decimal unicode �' => array( '�', '�' ),
     606            'Invalid hex unicode �'     => array( '�', '�' ),
     607        );
     608    }
     609
     610    /**
    554611     * @ticket 26290
    555      */
    556     public function test_wp_kses_normalize_entities() {
    557         $this->assertSame( '♠', wp_kses_normalize_entities( '♠' ) );
    558 
    559         $this->assertSame( '¹', wp_kses_normalize_entities( '¹' ) );
    560         $this->assertSame( '²', wp_kses_normalize_entities( '²' ) );
    561         $this->assertSame( '³', wp_kses_normalize_entities( '³' ) );
    562         $this->assertSame( '¼', wp_kses_normalize_entities( '¼' ) );
    563         $this->assertSame( '½', wp_kses_normalize_entities( '½' ) );
    564         $this->assertSame( '¾', wp_kses_normalize_entities( '¾' ) );
    565         $this->assertSame( '∴', wp_kses_normalize_entities( '∴' ) );
     612     *
     613     * @dataProvider data_normalize_entities
     614     */
     615    public function test_wp_kses_normalize_entities( string $input, string $expected ) {
     616        $this->assertSame( $expected, wp_kses_normalize_entities( $input ) );
    566617    }
    567618
Note: See TracChangeset for help on using the changeset viewer.