Files
wordpress-develop/tests/phpunit/tests/formatting/emoji.php
T
Jonathan Desrosiers 9b308c9fea Emoji: Replace twitter/twemoji with jdecked/twemoji.
After a chaotic change of ownership, the `twitter/twemoji` library is now considered abandoned.

After waiting for this moment to arise, a fork was created by several former employees who had maintained the library which lives at `jdecked/twemoji` on GitHub.

This switches out where the underlying source code comes from for the library, and applies the 15.0.3 update, which adheres to the Unicode 15 spec and adds support for all Emoji introduced in Emoji 15.0.

This does not update the underlying `precommit:emoji` Grunt script responsible for updating `formatting.php`. After GitHub recently sunset support for SVN, the current process needs to be replaced with a new one. This will be handled in #60520.

Let the masses rejoice for the 🐦‍⬛ singing in the dead of night, secure 🛜, aromatic 🫚, and some very silly 🪿🪿.

RIP Twemoji. Long live Twemoji!

Props peterwilsoncc, kraftbj, jeffpaul, azaozz, dd32, hareesh-pillai, jorbin.
Fixes #57600.

git-svn-id: https://develop.svn.wordpress.org/trunk@57626 602fd350-edb4-49c9-b593-d223f7449a82
2024-02-13 14:34:17 +00:00

173 lines
5.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* @group formatting
* @group emoji
*/
class Tests_Formatting_Emoji extends WP_UnitTestCase {
private $png_cdn = 'https://s.w.org/images/core/emoji/15.0.3/72x72/';
private $svn_cdn = 'https://s.w.org/images/core/emoji/15.0.3/svg/';
/**
* @ticket 36525
*
* @covers ::_print_emoji_detection_script
*/
public function test_unfiltered_emoji_cdns() {
// `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present:
self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
$output = get_echo( '_print_emoji_detection_script' );
$this->assertStringContainsString( wp_json_encode( $this->png_cdn ), $output );
$this->assertStringContainsString( wp_json_encode( $this->svn_cdn ), $output );
}
public function _filtered_emoji_svn_cdn( $cdn = '' ) {
return 'https://s.wordpress.org/images/core/emoji/svg/';
}
/**
* @ticket 36525
*
* @covers ::_print_emoji_detection_script
*/
public function test_filtered_emoji_svn_cdn() {
$filtered_svn_cdn = $this->_filtered_emoji_svn_cdn();
add_filter( 'emoji_svg_url', array( $this, '_filtered_emoji_svn_cdn' ) );
// `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present:
self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
$output = get_echo( '_print_emoji_detection_script' );
$this->assertStringContainsString( wp_json_encode( $this->png_cdn ), $output );
$this->assertStringNotContainsString( wp_json_encode( $this->svn_cdn ), $output );
$this->assertStringContainsString( wp_json_encode( $filtered_svn_cdn ), $output );
remove_filter( 'emoji_svg_url', array( $this, '_filtered_emoji_svn_cdn' ) );
}
public function _filtered_emoji_png_cdn( $cdn = '' ) {
return 'https://s.wordpress.org/images/core/emoji/png_cdn/';
}
/**
* @ticket 36525
*
* @covers ::_print_emoji_detection_script
*/
public function test_filtered_emoji_png_cdn() {
$filtered_png_cdn = $this->_filtered_emoji_png_cdn();
add_filter( 'emoji_url', array( $this, '_filtered_emoji_png_cdn' ) );
// `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present:
self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
$output = get_echo( '_print_emoji_detection_script' );
$this->assertStringContainsString( wp_json_encode( $filtered_png_cdn ), $output );
$this->assertStringNotContainsString( wp_json_encode( $this->png_cdn ), $output );
$this->assertStringContainsString( wp_json_encode( $this->svn_cdn ), $output );
remove_filter( 'emoji_url', array( $this, '_filtered_emoji_png_cdn' ) );
}
/**
* @ticket 41501
*
* @covers ::_wp_emoji_list
*/
public function test_wp_emoji_list_returns_data() {
$default = _wp_emoji_list();
$this->assertNotEmpty( $default, 'Default should not be empty' );
$entities = _wp_emoji_list( 'entities' );
$this->assertNotEmpty( $entities, 'Entities should not be empty' );
$this->assertIsArray( $entities, 'Entities should be an array' );
// Emoji 15 contains 3718 entities, this number will only increase.
$this->assertGreaterThanOrEqual( 3718, count( $entities ), 'Entities should contain at least 3718 items' );
$this->assertSame( $default, $entities, 'Entities should be returned by default' );
$partials = _wp_emoji_list( 'partials' );
$this->assertNotEmpty( $partials, 'Partials should not be empty' );
$this->assertIsArray( $partials, 'Partials should be an array' );
// Emoji 15 contains 1424 partials, this number will only increase.
$this->assertGreaterThanOrEqual( 1424, count( $partials ), 'Partials should contain at least 1424 items' );
$this->assertNotSame( $default, $partials );
}
public function data_wp_encode_emoji() {
return array(
array(
// Not emoji.
'',
'',
),
array(
// Simple emoji.
'🙂',
'&#x1f642;',
),
array(
// Bird, ZWJ, black large squre, emoji selector.
'🐦‍⬛',
'&#x1f426;&#x200d;&#x2b1b;',
),
array(
// Unicode 10.
'🧚',
'&#x1f9da;',
),
);
}
/**
* @ticket 35293
* @dataProvider data_wp_encode_emoji
*
* @covers ::wp_encode_emoji
*/
public function test_wp_encode_emoji( $emoji, $expected ) {
$this->assertSame( $expected, wp_encode_emoji( $emoji ) );
}
public function data_wp_staticize_emoji() {
$data = array(
array(
// Not emoji.
'',
'',
),
array(
// Simple emoji.
'🙂',
'<img src="' . $this->png_cdn . '1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
array(
// Skin tone, gender, ZWJ, emoji selector.
'👮🏼‍♀️',
'<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="👮🏼‍♀️" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
array(
// Unicode 10.
'🧚',
'<img src="' . $this->png_cdn . '1f9da.png" alt="🧚" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
),
);
return $data;
}
/**
* @ticket 35293
* @dataProvider data_wp_staticize_emoji
*
* @covers ::wp_staticize_emoji
*/
public function test_wp_staticize_emoji( $emoji, $expected ) {
$this->assertSame( $expected, wp_staticize_emoji( $emoji ) );
}
}