Skip to content

Tests: Cover wp_enqueue_code_editor() when syntax highlighting is disabled - #16238

Open
shail-mehta wants to merge 6 commits into
WordPress:trunkfrom
shail-mehta:tests/66757-enqueue-code-editor-syntax
Open

shail-mehta wants to merge 6 commits into
WordPress:trunkfrom
shail-mehta:tests/66757-enqueue-code-editor-syntax

Conversation

@shail-mehta

@shail-mehta shail-mehta commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: #66828

What

Adds a unit test for wp_enqueue_code_editor() asserting that it returns false when a logged-in user has syntax_highlighting set to 'false'.

Why

Existing Custom HTML widget tests fail if the syntax_highlighting guard is removed, but changing the disabled return value from false to null still leaves them green.

How

Creates a logged-in user, sets syntax_highlighting to 'false', calls wp_enqueue_code_editor( array( 'type' => 'text/css' ) ), and asserts false directly.

Testing Instructions

  • npm run test:php -- --filter Tests_General_WpEnqueueCodeEditor: 1 test passes.
  • Change the disabled early return from false to null: the test fails.
  • PHPCS reports no issues.

Use of AI Tools

  • Cursor

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 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_highlighting set to 'false'.
  • Asserts that the function returns false and 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

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 leaves script/style registries shared, allowing a previously enqueued code-editor to cause assertion failures despite a correct early return.

1 open issue
1 resolved since last review

Review effort: Balanced

shail-mehta and others added 2 commits November 25, 2026 16:28
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

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 recorded for the added regression coverage of disabled syntax highlighting.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review November 25, 2026 14:32
@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 shailu25, 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.

);
$this->assertFalse( wp_script_is( 'code-editor', 'enqueued' ) );
$this->assertFalse( wp_style_is( 'code-editor', 'enqueued' ) );
}

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 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:

Suggested change
}
}
/**
* 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 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.

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

@shail-mehta

Copy link
Copy Markdown
Member Author

Thanks for the review.

Addressed:

  • Kept only the focused assertFalse() return check for wp_enqueue_code_editor().
  • Removed the $wp_scripts / $wp_styles setup/teardown and the queue assertions.
  • Linked the General component ticket: https://core.trac.wordpress.org/ticket/66828 (@ticket and PR description updated).

Mukesh's empty-settings filter case is a separate behavior, so I've left it out of this PR.

Ready for another look.

@shail-mehta shail-mehta self-assigned this Nov 26, 2026

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

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

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.

4 participants