Make WordPress Core

Changeset 57861


Ignore:
Timestamp:
03/21/2024 03:45:56 PM (4 weeks ago)
Author:
SergeyBiryukov
Message:

Tests: Remove unnecessary use of utf8_encode() in KSES tests.

One of the tests for the wp_kses_xml_named_entities() function used utf8_encode( chr( 160 ) ) to set an expectation of a Unicode character for a non-breaking space.

It is understandable that this expectation was previously set this way, as it is not possible for a developer to distinguish between a breaking space and a non-breaking space visually, so the chances of the test accidentally breaking on an incorrect save when the plain Unicode character would be used, was high.

However, the utf8_encode() function is deprecated as of PHP 8.2, and its use needs to be removed from the WP codebase.

PHP 7.0 has introduced Unicode escape sequences, which allows to create a text string using Unicode characters referenced by their codepoint. By switching the test case to provide the test expectation using a Unicode escape sequence, we remove the use of the deprecated PHP function and still preserve the safeguard against the test accidentally breaking.

Follow-up to [52229].

Props jrf, afercia, poena, SergeyBiryukov.
See #55603, #60705.

File:
1 edited

Legend:

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

    r57228 r57861  
    21412141            'nbsp'               => array(
    21422142                'input'    => array( '', 'nbsp' ),
    2143                 'expected' => utf8_encode( chr( 160 ) ),
     2143                'expected' => "\u{00A0}",
    21442144            ),
    21452145            'iexcl'              => array(
Note: See TracChangeset for help on using the changeset viewer.