Skip to content

Add tests for print_emoji_detection_script function - #5912

Closed
pbearne wants to merge 5 commits into
WordPress:trunkfrom
pbearne:60306-wp_enqueue_emoji_styles
Closed

pbearne wants to merge 5 commits into
WordPress:trunkfrom
pbearne:60306-wp_enqueue_emoji_styles

Conversation

@pbearne

@pbearne pbearne commented Jan 19, 2024 •

Copy link
Copy Markdown

A new unit test file is created to ensure that the print_emoji_detection_script function works correctly. The tests check whether the final output contains the expected string and ensure no output when printing the emoji detection script again.

Trac ticket: https://core.trac.wordpress.org/ticket/60301

A new unit test file is created to ensure that the print_emoji_detection_script function works correctly. The tests check whether the final output contains the expected string and ensure no output when printing the emoji detection script again.
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@github-actions

github-actions Bot commented Feb 28, 2024 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props pbearne, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Renamed the PHPUnit test file from focusing on the Emoji detection script to instead focus on the enqueueing of Emoji styles. The changes include adjusting test class and function names, and modifying asserted outputs to align with the new focus.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests leave shared $wp_styles state mutated, risking order-dependent failures, and omit coverage of the promised emoji detection-script behavior.

2 open issues
What changed in this PR

Adds a PHPUnit test to WordPress’s formatting suite for emoji stylesheet enqueueing.

Changes:

  • Checks that enqueueing removes the legacy print_emoji_styles callback.
  • Verifies that printed styles contain the expected inline-style identifier and emoji selectors.
File Description
tests/​phpunit/​tests/​formatting/​wpEnqueueEmojiStyles.php Adds coverage for wp_enqueue_emoji_styles() hook removal and CSS output.

Review effort: Balanced


$this->assertSame( 10, has_action( 'wp_print_styles', 'print_emoji_styles' ) );

wp_enqueue_emoji_styles();
Comment on lines +19 to +25
wp_enqueue_emoji_styles();

$this->assertFalse( has_action( 'wp_print_styles', 'print_emoji_styles' ) );

$styles = get_echo( 'wp_print_styles' );
$this->assertStringContainsString( 'wp-emoji-styles-inline-css', $styles );
$this->assertStringContainsString( 'img.wp-smiley, img.emoji', $styles );

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style-enqueue check passed alone (one test, four assertions) and alongside existing emoji/style tests. The multisite group passed 99 tests and 226 assertions. The single-site group’s only failure was in the separate widget-menu proposal, #5830.

Please correct the copied title/docblock to describe style enqueuing; do not add detection-script tests, which current trunk already covers. Copilot’s shared-style-state observation is worth following up if an existing test/order exposes it. These local runs did not demonstrate an affected consumer, so additional isolation benefit remains unproven. This older head has no current CI checks; run CI before landing.

AI review · gpt-6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test does not isolate or restore the shared $wp_styles object, making its assertions dependent on prior tests and leaving state that can affect subsequent tests.

4 open issues

Review effort: Balanced

Comment on lines +15 to +26
public function test_wp_enqueue_emoji_styles() {

$this->assertSame( 10, has_action( 'wp_print_styles', 'print_emoji_styles' ) );

wp_enqueue_emoji_styles();

$this->assertFalse( has_action( 'wp_print_styles', 'print_emoji_styles' ) );

$styles = get_echo( 'wp_print_styles' );
$this->assertStringContainsString( 'wp-emoji-styles-inline-css', $styles );
$this->assertStringContainsString( 'img.wp-smiley, img.emoji', $styles );
}
Comment on lines +15 to +26
public function test_wp_enqueue_emoji_styles() {

$this->assertSame( 10, has_action( 'wp_print_styles', 'print_emoji_styles' ) );

wp_enqueue_emoji_styles();

$this->assertFalse( has_action( 'wp_print_styles', 'print_emoji_styles' ) );

$styles = get_echo( 'wp_print_styles' );
$this->assertStringContainsString( 'wp-emoji-styles-inline-css', $styles );
$this->assertStringContainsString( 'img.wp-smiley, img.emoji', $styles );
}
wporg-sync pushed a commit that referenced this pull request Oct 31, 2026
Check that `wp_enqueue_emoji_styles()` removes the legacy style-printing callback and emits the expected inline emoji styles.

Developed in: #5912

Props pbearne.
See #60301.


git-svn-id: https://develop.svn.wordpress.org/trunk@65144 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 31, 2026
Check that `wp_enqueue_emoji_styles()` removes the legacy style-printing callback and emits the expected inline emoji styles.

Developed in: WordPress/wordpress-develop#5912

Props pbearne.
See #60301.

Built from https://develop.svn.wordpress.org/trunk@65144


git-svn-id: http://core.svn.wordpress.org/trunk@64293 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants