Repository navigation
Tests: Cover wp_enqueue_code_editor() when syntax highlighting is disabled - #16238
shail-mehta wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new regression test lacks a .php extension, so the standard PHPUnit suites never discover or run it.
1 open issue
What changed in this PR
Adds a regression test for wp_enqueue_code_editor()’s early return when a logged-in user disables syntax highlighting, addressing Trac #66757.
Changes:
- Creates a user with
syntax_highlightingset to'false'. - Asserts that the function returns
falseand leaves the code-editor script and style unenqueued.
| File | Description |
|---|---|
tests/phpunit/tests/general/wpEnqueueCodeEditor |
Adds coverage for the syntax-highlighting-disabled early return. |
Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
| ); | ||
| $this->assertFalse( wp_script_is( 'code-editor', 'enqueued' ) ); | ||
| $this->assertFalse( wp_style_is( 'code-editor', 'enqueued' ) ); | ||
| } |
There was a problem hiding this comment.
The other early return, for empty filtered settings, isn't covered anywhere. When I removed the empty( $settings ) || empty( $settings['codemirror'] ) check, the existing code editor, script and widget tests all still passed. This test covers it, and it fails with that check removed:
| } | |
| } | |
| /** | |
| * Tests that nothing is enqueued when the filtered settings have no CodeMirror settings. | |
| * | |
| * @ticket 66757 | |
| */ | |
| public function test_wp_enqueue_code_editor_returns_false_when_settings_are_empty() { | |
| add_filter( 'wp_code_editor_settings', '__return_false' ); | |
| $this->assertFalse( wp_enqueue_code_editor( array( 'type' => 'text/css' ) ), 'The function should return false.' ); | |
| $this->assertFalse( wp_script_is( 'code-editor', 'enqueued' ), 'The code editor script should not be enqueued.' ); | |
| $this->assertFalse( wp_style_is( 'code-editor', 'enqueued' ), 'The code editor style should not be enqueued.' ); | |
| } |
lancewillett
left a comment
There was a problem hiding this comment.
I checked both tests. Removing the highlighting guard fails the existing Custom HTML widget test as well as this one. Changing just the disabled return from false to null leaves the widget test green and fails your new assertion. Please keep the focused assertFalse() return check and drop the asset-registry setup and teardown if you drop the queue assertions. The empty-settings filter Mukesh identified is a separate behavior.
Before landing, please link a ticket in the component that owns the code under test, per the 7.3 ticket guidance. Related coverage can share a component ticket.
AI review · gpt-6.2-astra
|
Thanks for the review. Addressed:
Mukesh's empty-settings filter case is a separate behavior, so I've left it out of this PR. Ready for another look. |
lancewillett
left a comment
There was a problem hiding this comment.
Changing the disabled-user return value from false to null failed this assertion. The simplified test covers that return contract without building fresh script or style registries. It passed in both site modes.
AI review · gpt-6.2-astra

Trac ticket: #66828
What
Adds a unit test for
wp_enqueue_code_editor()asserting that it returnsfalsewhen a logged-in user hassyntax_highlightingset to'false'.Why
Existing Custom HTML widget tests fail if the
syntax_highlightingguard is removed, but changing the disabled return value fromfalsetonullstill leaves them green.How
Creates a logged-in user, sets
syntax_highlightingto'false', callswp_enqueue_code_editor( array( 'type' => 'text/css' ) ), and assertsfalsedirectly.Testing Instructions
npm run test:php -- --filter Tests_General_WpEnqueueCodeEditor: 1 test passes.falsetonull: the test fails.Use of AI Tools