Skip to content

Tests: Cover the invalid user setting fallback in wp_default_editor(). - #16222

Open
mukeshpanchal27 wants to merge 3 commits into
WordPress:trunkfrom
mukeshpanchal27:test/wp-default-editor-fallback
Open

mukeshpanchal27 wants to merge 3 commits into
WordPress:trunkfrom
mukeshpanchal27:test/wp-default-editor-fallback

Conversation

@mukeshpanchal27

@mukeshpanchal27 mukeshpanchal27 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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

Description

Follow-up to 65747, which added tests for wp_default_editor().

wp_default_editor() uses user_can_richedit() only when the user's editor setting holds a value other than tinymce, html, or test. Otherwise get_user_setting( 'editor', 'tinymce' ) decides the result, because wp_get_current_user() always returns a WP_User object. The tests from [65747] never reach this fallback branch.

This adds two invalid setting rows to the existing test_wp_default_editor_respects_user_setting() test, which now uses a data provider:

editor setting user_can_richedit() Expected
html true html
invalid true tinymce
invalid false html

The first row is the existing case. It now also sets user_can_richedit() to true, which shows that a valid setting wins even when rich editing is available. All three rows share the existing cookie and $_updated_user_settings cleanup.

Testing

  • npm run test:php -- --filter Tests_General_WpDefaultEditor: 5 tests pass on single site and multisite.
  • The test catches a broken fallback. When I changed the fallback to always return tinymce, the "invalid setting, rich editing unavailable" row failed.
  • PHPCS reports no issues.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the untested branch, writing the test, and drafting this description. I reviewed the result.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with Claude Code

When the user's `editor` setting is not `tinymce`, `html`, or `test`, `wp_default_editor()` falls back to `user_can_richedit()`. The existing tests do not reach this branch.

This adds a data-driven test for both results of `user_can_richedit()`.

See #65819.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 25, 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 mukesh27, 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 or WordPress.org 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 reported for this test-only change covering invalid editor-setting fallbacks.

No open issues 🎉

What changed in this PR

Adds regression coverage for the invalid user-setting fallback in wp_default_editor(), complementing the existing tests without changing production code.

Changes:

  • Tests editor=invalid with rich editing both available and unavailable, expecting tinymce and html respectively.
  • Cleans up the user settings cookie and restores the previous global settings state after each case.
File Description
tests/​phpunit/​tests/​general/​wpDefaultEditor.php Adds a data-driven test covering both invalid-setting fallback outcomes.

Review effort: Balanced

@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 invalid setting reaches a real fallback. Forcing it to return tinymce failed the html case locally.

Could you add the two invalid-setting rows to test_wp_default_editor_respects_user_setting() alongside the existing valid html row? That keeps both outcomes and gives the cookie and $_updated_user_settings cleanup one home. I tried all three rows on single-site and multisite.

For the new coverage, please link an Editor component ticket. The existing test can keep its historical ticket annotation. Core’s guidance on test-only changes.

AI review · gpt-6

mukeshpanchal27 and others added 2 commits November 25, 2026 21:14
…user setting test.

Add the two invalid setting cases to `test_wp_default_editor_respects_user_setting()` as data provider rows next to the valid `html` case, so the cookie and `$_updated_user_settings` cleanup lives in one place.

See #66757.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mukeshpanchal27

Copy link
Copy Markdown
Member Author

Thanks, @lancewillett. I moved the two invalid setting rows into test_wp_default_editor_respects_user_setting() in 8a4e3d6, so all three rows share one cleanup. The test passes on single-site and multisite, and the "rich editing unavailable" row fails when the fallback is forced to tinymce.

About the ticket: wpDefaultEditor.php was added in [65747] under #65819 during the 7.2 cycle, and this PR is a direct follow-up that adds rows to one of those tests. Do we still need a separate Editor ticket for it? If so, I'll open one and update the annotations.

@lancewillett
lancewillett requested a balanced review from Copilot November 25, 2026 16:27

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

Yes, please open an Editor ticket for this follow-up and link it in the PR body. The existing test can keep its historical #65819 annotation. The shared fixture looks good. I ran the revised class in both modes and forcing the fallback to TinyMCE failed the rich-editing-unavailable row.

AI review · gpt-6.2-astra

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 remain for the test-only expansion of editor-setting fallback coverage.

No open issues 🎉

Review effort: Balanced

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

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants