Make WordPress Core

Opened 42 hours ago

Last modified 23 hours ago

#66818 new enhancement

Test the default editor when a saved editor preference is invalid

Reported by: lancewillett Owned by:
Priority: normal Milestone: 7.3
Component: Editor Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

[65747] covers the default editor and an explicitly saved preference. If a user has an unrecognized editor setting, wp_default_editor() falls back to whether that user can use the rich editor. Cover both outcomes so a change that always selects TinyMCE or always selects HTML will fail.

Patch and test results: ​https://github.com/WordPress/wordpress-develop/pull/16222

Change History (3)

This ticket was mentioned in ​PR #16222 on ​WordPress/wordpress-develop by ​@mukesh27.


42 hours ago
#1

  • Keywords has-patch has-unit-tests added

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

#2 @lancewillett
41 hours ago

#66819 was marked as a duplicate.

#3 @anntrauf
23 hours ago

Tested PR #16222 locally against the latest trunk.

Single-site testing:

  • Trunk (without patch): 3 tests passed, 3 assertions.
  • PR patch: 5 tests passed, 5 assertions.

Multisite testing:

  • PR patch: 5 tests passed, 5 assertions.

Verified the expected fallback behavior for invalid saved editor preferences with both rich editing enabled and disabled.

All tests passed with no failures or errors.

Result: Tested successfully.

Note: See TracTickets for help on using tickets.