Tests: Use unique data set keys in data_utf8_substrings()#12302
Conversation
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…tarts. In the non-UTF-8 byte-stream path, `_mb_substr()` delegates to `substr()`, which returns `false` for a start beyond the string length on PHP < 8.0, whereas `mb_substr()` returns an empty string on all versions. Normalize the result so the polyfill matches native `mb_substr()` behavior. This surfaced via the restored data sets in `Tests_Compat_mbSubstr::test_8bit_mb_substr()`.
| * empty string on PHP >= 8.0. mb_substr() always returns an empty string, | ||
| * so normalize to match its behavior across all supported PHP versions. | ||
| */ | ||
| return false === $result ? '' : $result; |
There was a problem hiding this comment.
this does normalize behavior to PHP 8.0+ right? which might leave it operating differently on a pre-PHP-8.0 site?
Description
Tests_Compat_mbSubstr::data_utf8_substrings()declared every data set with the same array key'баба'. Since PHP keeps only the last value for a duplicate array key, all but the final'баба'entry were silently discarded — only 2 of the 12 intended cases were actually executed bytest_mb_substr()andtest_8bit_mb_substr().This change replaces the duplicated keys with unique, descriptive ones that name the
$start/$lengthscenario each case covers (e.g.negative start, positive length,start beyond length, large negative length). All previously dropped cases now run, and failures point directly to the relevant scenario.The duplicate keys were introduced in [60969].
While restoring the previously-dropped data sets, two
test_8bit_mb_substr()cases with an out-of-range start (('баба', 30, 1)and('баба', 15, -30)) failed on PHP 7.4:_mb_substr()returnedfalsewhere nativemb_substr()returns''. In the non-UTF-8 path_mb_substr()delegates tosubstr(), which returnsfalsefor a start beyond the string length on PHP < 8.0. This PR normalizes that result to an empty string so the polyfill matches nativemb_substr()on all supported PHP versions.Testing instructions
Run the affected tests:
npm run test:php -- --filter Tests_Compat_mbSubstr tests/phpunit/tests/compat/mbSubstr.phpBefore: (23 tests)
Now: (43 tests) - the data provider now contributes 12 distinct cases per test method instead of 2.
Trac ticket: https://core.trac.wordpress.org/ticket/64894
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.