Skip to content

Tests: Cover format_to_edit() - #15317

Closed
devmuhib009 wants to merge 1 commit into
WordPress:trunkfrom
devmuhib009:tests/65819-cover-format-to-edit
Closed

devmuhib009 wants to merge 1 commit into
WordPress:trunkfrom
devmuhib009:tests/65819-cover-format-to-edit

Conversation

@devmuhib009

Copy link
Copy Markdown
Member

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

This PR adds unit tests for format_to_edit() covering:

  • Textarea escaping when $rich_text is false (default)
  • Bypassing textarea escaping when $rich_text is true
  • Filtering with the format_to_edit filter hook

@github-actions

github-actions Bot commented Nov 1, 2026

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 devmuhib.

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.

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.

🟢 Approval recommended

No active review issues are identified for this test-only addition of PHPUnit coverage for format_to_edit().

No open issues 🎉

What changed in this PR

Adds PHPUnit coverage for WordPress’s format_to_edit() function, addressing Trac ticket #65819 without changing production behavior.

Changes:

  • Tests textarea escaping with both the default and explicit false rich-text argument.
  • Verifies that rich-text mode leaves content unescaped.
  • Confirms that the format_to_edit filter modifies content before escaping.
File Description
tests/​phpunit/​tests/​formatting/​formatToEdit.php Adds three tests covering escaping, rich-text mode, and filter behavior.

Review effort: Balanced

@huzaifaalmesbah huzaifaalmesbah 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.

I left a few small notes inline.

AI Review: Opus 5.5

$expected = '&lt;b&gt;&quot;hello&quot; &amp; &#039;world&#039;&lt;/b&gt;';

$this->assertSame( $expected, format_to_edit( $content ) );
$this->assertSame( $expected, format_to_edit( $content, false ) );

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.

This one looks like a small coverage gap: esc_textarea() differs from esc_html() by double-encoding existing entities, and the class still passes if the function switches to esc_html(). Could you add a case like $this->assertSame( 'AT&amp;amp;T', format_to_edit( 'AT&amp;T' ) );?

@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.

Reviewed the changed code against the implementation and existing coverage; no blocking issue found.

Validated with the related behavioral coverage patches on current trunk: 35 tests / 43 assertions in each of single-site and multisite, randomized seed 1101. No failures, errors, warnings, or skips.

Current-head CI and Copilot review checked.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Nov 1, 2026
Verify the HTML escaping and format handling in `format_to_edit()`.

Developed in: #15317

Props devmuhib, huzaifaalmesbah.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@65174 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 1, 2026
Verify the HTML escaping and format handling in `format_to_edit()`.

Developed in: WordPress/wordpress-develop#15317

Props devmuhib, huzaifaalmesbah.
See #65819.

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


git-svn-id: http://core.svn.wordpress.org/trunk@64323 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.

4 participants