Make WordPress Core


Ignore:
Timestamp:
07/14/2017 11:49:34 AM (9 years ago)
Author:
pento
Message:

Emoji: Fix some failing unit tests in PHP 5.2 and 5.3.

  • Older versions of PHP don't know how to html_entity_decode() emoji.
  • The fall back regex was a little too broad, catching characters that aren't emoji.

See #35293.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/Emoji.php

    r41043 r41045  
    102102                                '🧚',
    103103                        ),
    104 
    105104                );
    106105        }
     
    115114
    116115        public function data_wp_staticize_emoji() {
    117                 return array(
     116                $data = array(
    118117                        array(
    119118                                // Not emoji
     
    124123                                // Simple emoji
    125124                                '🙂',
    126                                 '<img src="' . $this->png_cdn . '1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     125                                '<img src="' . $this->png_cdn . '1f642.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    127126                        ),
    128127                        array(
    129128                                // Skin tone, gender, ZWJ, emoji selector
    130129                                '👮🏼‍♀️',
    131                                 '<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="👮🏼‍♀️" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     130                                '<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    132131                        ),
    133132                        array(
    134133                                // Unicode 10
    135134                                '🧚',
    136                                 '<img src="' . $this->png_cdn . '1f9da.png" alt="🧚" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     135                                '<img src="' . $this->png_cdn . '1f9da.png" alt="" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    137136                        ),
     137                );
    138138
    139                 );
     139                // Older versions of PHP don't html_entity_decode() emoji, so we need to make sure they're testing in the expected form.
     140                foreach ( $data as $key => $datum ) {
     141                        $emoji = html_entity_decode( wp_encode_emoji( $datum[0] ) );
     142                        $data[ $key ][1] = str_replace( 'alt=""', 'alt="' . $emoji . '"', $datum[1] );
     143                }
     144
     145                return $data;
    140146        }
    141147
Note: See TracChangeset for help on using the changeset viewer.