Make WordPress Core

Changeset 62207


Ignore:
Timestamp:
04/04/2026 11:17:45 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Tests: Adjust Unicode tests for consistency.

Includes:

  • Adding missing @covers tags.
  • Correcting test class names as per the naming conventions.
  • Moving wp_check_invalid_utf8() tests to their own file, separate from wp_scrub_utf8().

Follow-up to [60630], [60793], [61000].

See #64225.

Location:
trunk/tests/phpunit/tests/unicode
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/unicode/wpCheckInvalidUtf8.php

    r60796 r62207  
    11<?php
     2
    23/**
    34 * Unit tests covering WordPress’ UTF-8 handling.
     
    56 * @package WordPress
    67 * @group unicode
     8 *
     9 * @covers ::wp_check_invalid_utf8
    710 */
     11class Tests_Unicode_WpCheckInvalidUtf8 extends WP_UnitTestCase {
    812
    9 class Tests_WpScrubUtf8 extends WP_UnitTestCase {
    1013        /**
    1114         * Verifies that WordPress can properly detect valid and invalid UTF-8.
     
    4144                                $scrubbed,
    4245                                wp_check_invalid_utf8( $bytes, true ),
    43                                 'Failed to properly scrub the invalid spans of UTF-8 from the input string.'
    44                         );
    45                 }
    46         }
    47 
    48         /**
    49          * Verifies that WordPress can properly detect valid UTF-8 while replacing invalid byte sequences.
    50          *
    51          * @ticket 63837
    52          *
    53          * @dataProvider data_utf8_test_data
    54          *
    55          * @param string      $bytes    Bytes as a PHP string.
    56          * @param string|null $scrubbed Expected checked value, if string isn’t valid UTF-8.
    57          */
    58         public function test_properly_scrubs_utf8( string $bytes, ?string $scrubbed = null ) {
    59                 if ( null === $scrubbed ) {
    60                         $this->assertSame(
    61                                 $bytes,
    62                                 wp_scrub_utf8( $bytes ),
    63                                 'Should have returned the unchanged string for valid UTF-8 input.'
    64                         );
    65                 } else {
    66                         $this->assertSame(
    67                                 bin2hex( $scrubbed ),
    68                                 bin2hex( wp_scrub_utf8( $bytes ) ),
    69                                 'Failed to properly scrub the invalid spans of UTF-8 from the input string.'
    70                         );
    71                 }
    72         }
    73 
    74         /**
    75          * Verifies that WordPress’ fallback code can properly detect valid UTF-8
    76          * while replacing invalid byte sequences.
    77          *
    78          * @ticket 63837
    79          *
    80          * @dataProvider data_utf8_test_data
    81          *
    82          * @param string      $bytes    Bytes as a PHP string.
    83          * @param string|null $scrubbed Expected checked value, if string isn’t valid UTF-8.
    84          */
    85         public function test_fallback_properly_checks_utf8( string $bytes, ?string $scrubbed = null ) {
    86                 if ( null === $scrubbed ) {
    87                         $this->assertSame(
    88                                 $bytes,
    89                                 _wp_scrub_utf8_fallback( $bytes ),
    90                                 'Should have returned the unchanged string for valid UTF-8 input.'
    91                         );
    92                 } else {
    93                         $this->assertSame(
    94                                 bin2hex( $scrubbed ),
    95                                 bin2hex( _wp_scrub_utf8_fallback( $bytes ) ),
    9646                                'Failed to properly scrub the invalid spans of UTF-8 from the input string.'
    9747                        );
  • trunk/tests/phpunit/tests/unicode/wpHasNoncharacters.php

    r61000 r62207  
    55 * @package WordPress
    66 * @group unicode
     7 *
     8 * @covers ::wp_has_noncharacters
    79 */
     10class Tests_Unicode_WpHasNoncharacters extends WP_UnitTestCase {
    811
    9 class Tests_WpHasNoncharacters extends WP_UnitTestCase {
    1012        /**
    1113         * Ensures that a noncharacter inside a string will be properly detected.
  • trunk/tests/phpunit/tests/unicode/wpIsValidUtf8.php

    r60630 r62207  
    11<?php
     2
    23/**
    34 * Unit tests covering WordPress’ UTF-8 handling.
     
    56 * @package WordPress
    67 * @group unicode
     8 *
     9 * @covers ::wp_is_valid_utf8
    710 */
     11class Tests_Unicode_WpIsValidUtf8 extends WP_UnitTestCase {
    812
    9 class Tests_WpIsValidUtf8TestCase extends WP_UnitTestCase {
    1013        /**
    1114         * Verifies that WordPress can properly detect valid and invalid UTF-8.
  • trunk/tests/phpunit/tests/unicode/wpScrubUtf8.php

    r60793 r62207  
    11<?php
     2
    23/**
    34 * Unit tests covering WordPress’ UTF-8 handling.
     
    56 * @package WordPress
    67 * @group unicode
     8 *
     9 * @covers ::wp_scrub_utf8
    710 */
    8 
    9 class Tests_WpScrubUtf8 extends WP_UnitTestCase {
    10         /**
    11          * Verifies that WordPress can properly detect valid and invalid UTF-8.
    12          *
    13          * @ticket 63837
    14          *
    15          * @dataProvider data_utf8_test_data
    16          *
    17          * @param string      $bytes    Bytes as a PHP string.
    18          * @param string|null $scrubbed Expected checked value, if string isn’t valid UTF-8.
    19          */
    20         public function test_properly_checks_utf8( string $bytes, ?string $scrubbed = null ) {
    21                 if ( null === $scrubbed ) {
    22                         $this->assertSame(
    23                                 $bytes,
    24                                 wp_check_invalid_utf8( $bytes ),
    25                                 'Should have returned the unchanged string for valid UTF-8 input when not stripping invalid bytes.'
    26                         );
    27 
    28                         $this->assertSame(
    29                                 $bytes,
    30                                 wp_check_invalid_utf8( $bytes, true ),
    31                                 'Should have returned the unchanged string for valid UTF-8 input when stripping invalid bytes.'
    32                         );
    33                 } else {
    34                         $this->assertSame(
    35                                 '',
    36                                 wp_check_invalid_utf8( $bytes ),
    37                                 'Should have rejected invalid input, returning an empty string when not stripping invalid bytes.'
    38                         );
    39 
    40                         $this->assertSame(
    41                                 $scrubbed,
    42                                 wp_check_invalid_utf8( $bytes, true ),
    43                                 'Failed to properly scrub the invalid spans of UTF-8 from the input string.'
    44                         );
    45                 }
    46         }
     11class Tests_Unicode_WpScrubUtf8 extends WP_UnitTestCase {
    4712
    4813        /**
     
    8348         * @param string|null $scrubbed Expected checked value, if string isn’t valid UTF-8.
    8449         */
    85         public function test_fallback_properly_checks_utf8( string $bytes, ?string $scrubbed = null ) {
     50        public function test_fallback_properly_scrubs_utf8( string $bytes, ?string $scrubbed = null ) {
    8651                if ( null === $scrubbed ) {
    8752                        $this->assertSame(
Note: See TracChangeset for help on using the changeset viewer.