Skip to content

Add tests for wp_spaces_regexp function - #5924

Open
pbearne wants to merge 8 commits into
WordPress:trunkfrom
pbearne:60319-wp_spaces_regexp
Open

pbearne wants to merge 8 commits into
WordPress:trunkfrom
pbearne:60319-wp_spaces_regexp

Conversation

@pbearne

@pbearne pbearne commented Jan 22, 2024

Copy link
Copy Markdown

A new PHPUnit test file is added to check the functionality of the wp_spaces_regexp function in a WordPress application. These tests verify the return value of the function with given input and confirm the filter instantiation calls.

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

A new PHPUnit test file is added to check the functionality of the wp_spaces_regexp function in a WordPress application. These tests verify the return value of the function with given input and confirm the filter instantiation calls.
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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 covers only a warmed cache and would still pass if apply_filters() were removed, leaving cold-start filter behavior unverified.

1 open issue
What changed in this PR

Adds PHPUnit coverage for WordPress’s wp_spaces_regexp() function, associated with Trac ticket #60319.

Changes:

  • Checks the default whitespace regular expression.
  • Uses MockAction to verify that a newly registered filter is not invoked when the result is already cached.
File Description
tests/​phpunit/​tests/​formatting/​wpSpacesRegexp.php Adds assertions for the default pattern and warmed-cache filter behavior.

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 filter assertion only confirms that bootstrap already populated the static cache, and the exact regex string couples the test to implementation. Existing texturize checks cover whitespace behavior. Please identify a distinct behavioral regression before adding this check; no larger matrix is needed.

AI review · gpt-6

@github-actions

github-actions Bot commented Nov 2, 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 pbearne, 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.

🟡 Changes recommended

The isolated test still runs the WordPress bootstrap, which populates the regex cache before filter registration, causing the assertion to receive the default pattern and leaving the filter untested.

2 open issues

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.

🔵 Needs a closer look

The test fails to warm the current process’s cache before registering the mock, so correct cold-cache behavior can invoke the filter and fail the zero-call assertion.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Warm the static cache before attaching the mock

tests/​phpunit/​tests/​formatting/​wpSpacesRegexp.php:45

This test attaches the mock without first populating the current process's static cache; the cold-start test populates only its subprocess's cache. If no earlier call has warmed the cache, the call on line 47 invokes the filter and the zero-call assertion fails despite correct behavior. Call wp_spaces_regexp() before registering the mock so the test establishes its own warmed-cache precondition.

1 resolved since last review

Review effort: Balanced

@pbearne
pbearne requested a review from lancewillett November 3, 2026 00:08

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

Thanks, the cold-start test answers my question: it's the only test that catches wp_spaces_regexp() ignoring its filter, and it also catches a lost static cache. The class passes in randomized single-site and multisite runs alongside the wptexturize() tests.

test_wp_spaces_regexp_warmed_cache() doesn't add protection, though:

Change Caught by
Filter not applied cold-start test only
No static cache cold-start test, warmed-cache test
&nbsp; dropped from the default existing wptexturize() data sets (#4–#7), warmed-cache test

Its exact-string check duplicates the wptexturize() coverage and fails on any intentional pattern change. Its call-count check duplicates the cold-start test. Please remove it and keep the cold-start test.

AI review · claude-opus-5-5

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 unconditionally calls potentially disabled exec(), breaks valid pre-escaped WP_PHP_BINARY commands, and leaves the default whitespace expression and filter input unverified.

4 open issues

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.

Thanks for removing the warmed-cache test. The remaining case passed on single-site and multisite. I reproduced two portability issues before landing:

  • Please use the configured WP_PHP_BINARY the same way the test bootstrap does. With a valid pre-escaped path containing a space, installation succeeds but the test exits 127. Removing the second escape made all five assertions pass. Command construction
  • Please skip this subprocess test when exec() is unavailable. With WP_TESTS_SKIP_INSTALL=1 and exec disabled, the suite boots and the new test errors. Subprocess call

The coding standards job and local PHPCS both flag the blank line before the final class brace. Removing it clears the finding.

The existing wptexturize() cases already exercise the default whitespace expression. The cold-start case can stay focused on the filter and its cached result.

AI review · gpt-6.2-astra

pbearne and others added 2 commits November 26, 2026 14:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Skip the test when `exec()` is unavailable and correctly quote the fallback PHP binary.
Remove the assertion for the initial pattern passed to the filter.

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.

🔵 Needs a closer look

The test’s filter callback ignores the incoming pattern, allowing an incorrect default whitespace expression to pass without detection.

1 open issue
3 resolved since last review

Review effort: Balanced

@pbearne
pbearne requested a review from lancewillett November 26, 2026 19:57

@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 portability changes address my previous review. With the same cold-start test and a pre-escaped PHP path containing a space, the prior revision exited 127 and this revision passed. With exec disabled, the prior test errored and this revision skipped. The current head also passed in randomized single-site and multisite runs.

The Copilot note correctly observes that this callback ignores the incoming expression. This test checks whether the cold-start filter runs and whether its return value is cached. The existing wptexturize cases catch loss of default whitespace behavior, so I would keep this case focused on the filter and cache. The Formatting component review is still open.

AI review · gpt-6.2-astra

@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 revised cold-start test addresses my change request. It passed with a PHP binary path containing a space and skipped cleanly with exec disabled. Jonny’s independent Formatting review is still requested.

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.

3 participants