4301 Commits

Author SHA1 Message Date
Jonathan Desrosiers
44180691e6 Editor: Ensure block attribute serialization in PHP matches the JavaScript equivalent.
The `serializeAttributes()` function in JavaScript uses `JSON.stringify`, which does not encode slashes and unicode characters by default. This resulted in the PHP serialization through `json_encode()` producing different results.

This also switches from `json_encode()` to `wp_json_encode()` to prevent failures when any non UTF-8 characters are included.

Props kevinfodness, SergeyBiryukov, timothyblynjacobs.
Fixes #53936.

git-svn-id: https://develop.svn.wordpress.org/trunk@51674 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 19:09:16 +00:00
Tonya Mork
6201d437e8 Tests: Improve bootstrap error message for when ABSPATH folder does not exist.
The PHPUnit tests are/should generally be run on the `src` directory, so changes just made can be tested. While testing via the `build` directory is also still supported, this is not the default.

This was last changed in [50441], but that commit did not remove/update the error message thrown by the test bootstrap file.

This last change also did not take into account that that change meant that people had to update their own `wp`tests-config.php` file to match the change made in Core and would otherwise still get the outdated error message.

This commit changes the messaging in the test bootstrap file to be more in line with the current reality, while still accounting for the fact that tests can be run from both `src` as well as `build`.

Follow-up to [49569], [50441], [51581].
Props jrf, hellofromTonya.

git-svn-id: https://develop.svn.wordpress.org/trunk@51669 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 17:55:02 +00:00
SergeyBiryukov
d616b931e0 Coding Standards: Add missing visibility keywords for wp_filter_object_list() and wp_list_pluck() tests.
Follow-up to [51663-51667].

Props pbearne.
See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51668 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:50:02 +00:00
Sergey Biryukov
72de4966b8 Tests: Move wp_list_sort() tests to their own file.
This matches the name of the function being tested.

Follow-up to [38928], [51663-51666].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51667 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:29:37 +00:00
Sergey Biryukov
cd1f879ced Tests: Move wp_list_filter() tests to their own file.
This matches the name of the function being tested.

Follow-up to [38928], [51663-51665].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51666 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:20:57 +00:00
Sergey Biryukov
b683b830ab Tests: Rename the test file and class for wp_filter_object_list() tests.
This matches the name of the function being tested.

Follow-up to [410/tests], [51663], [51664].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51665 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:08:48 +00:00
Sergey Biryukov
a90e7eb5ff Tests: Remove duplicate wp_list_pluck() tests.
The tests were partially duplicated in two separate files, and are now located in their own file.

Follow-up to [431/tests], [28900], [38928], [42527], [51663].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51664 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:02:13 +00:00
Sergey Biryukov
927bc80b92 Tests: Move wp_list_pluck() tests to their own file.
The tests were partially duplicated in two separate files.

Follow-up to [431/tests], [28900], [38928], [42527].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51663 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 15:54:29 +00:00
Tonya Mork
e83a341cc0 Coding Standards: Use static closures when not using $this.
When a closure does not use `$this`, it can be made `static` for improved performance.

Static closures are supported in PHP since PHP 5.4. ​

Props jrf, hellofromTonya, swissspidy, SergeyBiryukov.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51657 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 12:57:08 +00:00
Andrew Ozz
67f8702477 Media: Fix wp_unique_filename() to check for name collisions with all alternate file names when an image may be converted after uploading. This includes possible collinions with pre-existing images whose sub-sizes/thumbnails are regenerated.
Props ianmjones, azaozz.
Fixes #53668.

git-svn-id: https://develop.svn.wordpress.org/trunk@51653 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-24 20:50:21 +00:00
Sergey Biryukov
402e2e636b Tests: Rename classes in phpunit/tests/feed/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646], [51650].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51651 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-22 10:07:17 +00:00
Sergey Biryukov
43a8715ded Tests: Rename classes in phpunit/tests/error-protection/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51650 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-21 15:32:53 +00:00
Andrew Ozz
fe3d953437 REST API: Remove trailing slashes when preloading requests and add unit tests for it.
Props antonvlasenko.
Fixes #51636.

git-svn-id: https://develop.svn.wordpress.org/trunk@51648 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-20 23:43:21 +00:00
Sergey Biryukov
ee81f71ac6 Tests: Rename classes in phpunit/tests/editor/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51646 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-20 16:11:04 +00:00
Sergey Biryukov
0778740cb4 Tests: Move loading the WP_Community_Events class to set_up_before_class().
This ensures that the class is loaded once before the first test of the test case class is run, and `require_once()` is not unnecessarily called for each test method individually.

Follow-up to [40607], [51628].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51641 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-19 13:59:36 +00:00
Sergey Biryukov
e20beacb6e Tests: Rename classes in phpunit/tests/admin/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51639 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-19 13:08:43 +00:00
Sergey Biryukov
05f28947e7 Media: Check the return type of _get_cron_array() in WP_Media_List_Table::prepare_items().
The following warnings could, in very select circumstances, be shown:
{{{
// PHP 8.0 and higher:
Warning: foreach() argument must be of type array|object, bool given

// PHP 5.6 – 7.4
Warning: Invalid argument supplied for foreach()
}}}

In `WP_Media_List_Table::prepare_items()`, the cron info array is retrieved via a call to `_get_cron_array()`, but as the documentation (correctly) states, the return type of that function is `array|false`, where `false` is returned for a virgin site, with no cron jobs scheduled yet.

However, no type check is done on the return value, and the method just blindly continues by using it in a `foreach`.

Fixed by adding validation for the returned value from `_get_cron_array()` and only running the `foreach` when the returned value is an array.

Reference: [https://developer.wordpress.org/reference/functions/_get_cron_array/ WordPress Developer Resources: _get_cron_array()]

Follow-up to [48417].

Props jrf, hellofromTonya, mukesh27.
Fixes #53949.

git-svn-id: https://develop.svn.wordpress.org/trunk@51638 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-19 12:43:03 +00:00
Sergey Biryukov
16b448416b Tests: Move loading the PO class to set_up_before_class().
This ensures that the class is loaded once before the first test of the test case class is run, and `require_once()` is not unnecessarily called for each test method individually.

Follow-up to [1106/tests].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51628 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-17 20:01:15 +00:00
Sergey Biryukov
6d574d7cab Tests: Use a better return type check for parse_url() in do_enclose() tests.
Since the `pathinfo()` function accepts a string, checking for that specifically is more consistent with similar checks elsewhere in core.

Follow-up to [51606], [51622], [51626].

See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51627 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-17 00:27:38 +00:00
Sergey Biryukov
5f5895bf61 Code Modernization: Check the return type of parse_url() in download_url().
As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

This commit adds three unit tests for `download_url()`:

* The first test is "girl-scouting" to make sure that the code up to the point where the error is expected is tested.
* The second test exposed a PHP 8.1 `basename(): Passing null to parameter #1 ($path) of type string is deprecated` error due to the call to `parse_url()` returning `null` when the component requested does not exist in the passed URL.
* The output of the call to `parse_url()` stored in the `$url_path` variable is used in more places in the function logic. The third test exposes a second PHP 8.1 deprecation notice, this time for `substr(): Passing null to parameter #1 ($string) of type string is deprecated`.

This commit also removes duplicate `parse_url()` calls. Neither `$url` nor `$url_filename` are changed between when they are first received/defined and when they are re-used, so there is no need to repeat the function calls.

Follow-up to [51606], [51622].

Props jrf, hellofromTonya, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51626 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-17 00:14:20 +00:00
Sergey Biryukov
d93f76dca8 Code Modernization: Correct handling of null in wp_parse_str().
This fixes `parse_str(): Passing null to parameter #1 ($string) of type string is deprecated` notices on PHP 8.1, without change in behaviour.

Impact: 311 of the pre-existing tests are affected by this issue.

The PHP native `parse_str()` function expects a string, however, based on the failing tests, it is clear there are functions in WordPress which passes a non-string – including `null` – value to the `wp_parse_str()` function, which would subsequently pass it onto the PHP native function without further input validation.

Most notable offender is the `wp_parse_args()` function which special cases arrays and objects, but passes everything else off to `wp_parse_str()`.

Several ways to fix this issue have been explored, including checking the received value with `is_string()` or `is_scalar()` before passing it off to the PHP native `parse_str()` function.

In the end it was decided against these in favor of a string cast as:
* `is_string()` would significantly change the behavior for anything non-string.
* `is_scalar()` up to a point as well, as it does not take objects with a `__toString()` method into account.

Executing a string cast on the received value before passing it on maintains the pre-existing behavior while still preventing the deprecation notice coming from PHP 8.1.

Reference: [https://www.php.net/manual/en/function.parse-str.php PHP Manual: parse_str()]

Follow-up to [5709].

Props jrf, hellofromTonya, lucatume, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51624 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-16 22:16:32 +00:00
Sergey Biryukov
4d2762ed93 Tests: Rename classes in phpunit/tests/formatting/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51623 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-16 21:33:54 +00:00
Sergey Biryukov
18bda14e1e Code Modernization: Check the return type of parse_url() in WP::parse_request().
As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

In this case, `parse_url()` is called with the `PHP_URL_PATH` as `$component`. This will return `null` in the majority of cases, as – exсept for subdirectory-based sites – `home_url()` returns a URL without the trailing slash, like `http://example.org`.

The return value of `parse_url()` was subsequently passed to `trim()`, leading to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1.

Fixed by adjusting the logic flow to:
* Only pass the return value of `parse_url()` to follow-on functions if it makes sense, i.e. if it isn't `null`, nor an empty string.
* Preventing calls to `preg_replace()` and `trim()` further down in the function logic flow, when `preg_replace()`/`trim()` would have nothing to do anyhow.

Follow-up to [25617].

Props jrf, hellofromTonya, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51622 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-16 20:16:13 +00:00
Sergey Biryukov
c9df4f75a2 Code Modernization: Check the return type of _get_cron_array() in wp_schedule_event().
This fixes a "Deprecated: Automatic conversion of false to array is deprecated" warning on PHP 8.1.

In `wp_schedule_event()`, the cron info array is retrieved via a call to `_get_cron_array()`, but as the documentation (correctly) states, the return type of that function is `array|false`, where `false` is returned for a virgin site, with no cron jobs scheduled yet.

However, no type check is done on the return value, and the `wp_schedule_event()` function just blindly continues by assigning a value to a subkey of the `$crons` "array".

Fixed by adding validation for the returned value from `_get_cron_array()` and initializing an empty array if `false` was returned.

Reference: [https://developer.wordpress.org/reference/functions/_get_cron_array/ WordPress Developer Resources: _get_cron_array()]

Props jrf, hellofromTonya, lucatume, pbearne, iluy, pedromendonca, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51619 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-16 15:22:38 +00:00
Sergey Biryukov
74edebac97 Tests: Add unit tests for the wp_nonce_ays() function.
Update the `wp_die_handler()` method to pass the response into `WPDieException` so that `expectExceptionCode()` calls work as expected.

Follow-up to [1221/tests], [3934], [4009], [12309].

Props pbearne, jrf, mukesh27.
Fixes #53882.

git-svn-id: https://develop.svn.wordpress.org/trunk@51608 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-13 14:00:05 +00:00
Sergey Biryukov
6406dbaca8 Tests: Use correct comparison in do_enclose() tests.
As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

In this case, `parse_url()` is called with the `PHP_URL_PATH` as `$component`, but the returned value is subsequently checked against `false`.

In other words, this condition would previously always result in `true` and would lead to `null` potentially being passed to the PHP native `pathinfo()` function which expects a string.

On PHP 8.1, this would result in a test failure with a `pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated` error.

Reference: [https://www.php.net/manual/en/function.pathinfo.php PHP Manual: pathinfo()]

Follow-up to [46175].

Props jrf.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51606 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-12 17:48:55 +00:00
Sergey Biryukov
2985e902d4 Build/Test Tools: Hard deprecate WP_UnitTestCase_Base::checkRequirements().
The `WP_UnitTestCase_Base::checkRequirements()` method calls the `parent::checkRequirements()` method, but this method became `private` in PHPUnit 7.0 via commit  [932238a6a3 sebastianbergmann/phpunit@932238a].

Aside from that, the `TestCase::getAnnotations()` method which is called next is now also removed in PHPUnit 9.5.

WP core does not use the method anymore, and the method only remains to prevent potentially breaking external integration tests relying on the method. However, in effect, the method is not functional anymore in PHPUnit 7.0+.

Follow-up to [893/tests], [894/tests], [896/tests], [918/tests], [30526], [40520], [40564], [43005], [44701], [51559-51577].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51605 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-12 10:32:24 +00:00
Sergey Biryukov
f7a7025899 Build/Test Tools: Revert [51602] for now to investigate test failures on PHPUnit < 7.0.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51603 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-11 15:01:16 +00:00
Sergey Biryukov
7a6dbf5056 Build/Test Tools: Hard deprecate WP_UnitTestCase_Base::checkRequirements().
The `WP_UnitTestCase_Base::checkRequirements()` method calls the `parent::checkRequirements()` method, but this method became `private` in PHPUnit 7.0 via commit  [932238a6a3 sebastianbergmann/phpunit@932238a].

Aside from that, the `TestCase::getAnnotations()` method which is called next is now also removed in PHPUnit 9.5.

WP core does not use the method anymore, and the method only remains to prevent potentially breaking external integration tests relying on the method. However, in effect, the method is not functional anymore in PHPUnit 7.0+.

Follow-up to [893/tests], [894/tests], [896/tests], [918/tests], [30526], [40520], [40564], [43005], [44701], [51559-51577].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51602 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-11 14:30:29 +00:00
Greg Ziółkowski
18024e62d7 Tests: Fix failing i18n unit tests for block metadata
Follow up for #53238.

Changes to the translation file weren't included in [51599].



git-svn-id: https://develop.svn.wordpress.org/trunk@51600 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-11 10:37:17 +00:00
Greg Ziółkowski
d9599addd1 Blocks: Add support for variations in block.json` file
We integrated variations with block types and the corresponding REST API endpoint in #52688. It's a follow-up patch to add missing support to the `block.json` metadata file when using `register_block_type`.

Some fields for variations are translatable.Therefore, i18n schema was copied over from Gutenberg: https://github.com/WordPress/gutenberg/blob/trunk/packages/blocks/src/api/i18n-block.json. The accompanying implementation was adapted as `translate_settings_using_i18n_schema`.

Props: gwwar, swissspidy, schlessera, jorgefilipecosta.
Fixes #53238.



git-svn-id: https://develop.svn.wordpress.org/trunk@51599 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-11 09:06:31 +00:00
Sergey Biryukov
9b565f7907 Build/Test Tools: Make the polyfills loading more flexible.
The PHPUnit Polyfills are, since [51559], a required dependency for the WP test suite and, by extension, for plugin/theme integration test suites which are based on and use (parts of) the WP core test suite.

However, plugin/theme integration test suites may not use a full WordPress installation.

This commit:
* Removes the presumption that a full WP install, including `vendor` directory, will be available when the test `bootstrap.php` file is run.
* Makes the loading of the PHPUnit Polyfills autoload file more flexible by:
  * Checking if the autoload class contained within the autoload file is already available before attempting to load the file.[[BR]]
    This allows for plugin/theme integration test suites to load the `phpunitpolyfills-autoload.php` file from any location, as long as it is loaded before the WP core test `bootstrap.php` file is run.
  * Allowing for the path to an arbitrary installation location for the PHPUnit Polyfills to be passed as a constant.[[BR]]
    As long as the provided location is a valid file path and the `phpunitpolyfills-autoload.php` file exists in the provided location, that file will be loaded.[[BR]]
    The constant can be declared in a plugin/theme integration test suite native test bootstrap file, or in the `wp-tests-config.php` file, or even in a `phpunit.xml[.dist]` file via `<php><const name="WP_TESTS_PHPUNIT_POLYFILLS_PATH" value="path/to/yoast/phpunit-polyfills"/></php>`.
* Adds a version check for the PHPUnit Polyfills to prevent a mismatch between the version of the package expected by WordPress and the version used by plugins/themes.[[BR]]
  The version this checks for should be in line with the minimum version requirement for the PHPUnit Polyfills as declared in the `composer.json` file.[[BR]]
  This version number should only be updated when new features added in later PHPUnit Polyfills releases are actually used in the WP core test suite.
* Adds appropriate error messages for every possible error condition.
* Upgrades the PHPUnit Polyfills to version 1.0.1, which now includes a version constant.

Follow-up to [51559-51577].

Props jrf, hellofromTonya, swissspidy, jeherve, thomasplevy, SergeyBiryukov.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51598 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-10 21:13:38 +00:00
Sergey Biryukov
2af80e6cbe Code Modernization: Silence the deprecation warning for missing return type in phpunit/tests/compat.php.
This fixes the "Deprecated: Return type of `CountableFake::count()` should be compatible with `Countable::count(): int`" warning on PHP 8.1.

PHP native interfaces now have declared return types and methods in classes implementing these interfaces need to either have the return type declared (in a covariant compatible manner with the PHP native interface method declaration), or need to silence the deprecation warning using the `#[ReturnTypeWillChange]` attribute.

Follow-up to [51517], [51529], [51530], [51531], [51532].

Props jrf.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51594 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-10 17:34:30 +00:00
Sergey Biryukov
b9351465d6 Code Modernization: Replace strftime() and gmstrftime() usage in unit tests.
Since PHP 8.1, the `strftime()` and `gmstrftime()` functions are deprecated:

> The `strftime()` and `gmstrftime()` functions exhibit similar issues as `strptime()`, in that the formats they support, as well as their behavior, is platform-dependent. Unlike `strptime()`, these functions are available on Windows, though with a different feature set than on Linux. Musl-based distributions like Alpine do not support timezone-related format specifiers correctly. These functions are also locale-based, and as such may exhibit thread-safety issues.
>
> `date()` or `DateTime::format()` provide portable alternatives, and `IntlDateFormatter::format()` provides a more sophisticated, localization-aware alternative.

Reference: [https://wiki.php.net/rfc/deprecations_php_8_1#strftime_and_gmstrftime PHP RFC: Deprecations for PHP 8.1: strftime() and gmstrftime()]

> The `strftime()` and `gmstrftime()` functions have been deprecated in favor of
> `date()/DateTime::format()` (for locale-independent formatting) or
> `IntlDateFormatter::format()` (for locale-dependent formatting).

Reference: [1cf4fb739f/UPGRADING (L379-L381) PHP 8.1 Upgrade Notes].

Aside from one instance in SimplePie, the `strftime()` and `gmstrftime()` functions are only used within the test suite of WordPress to create formatted timestamps.

As the function is used in test code, this leads to test warnings like this on PHP 8.1:
{{{
Deprecated: Function strftime() is deprecated in path/to/tests/phpunit/tests/canonical/postStatus.php on line 37
}}}

These calls can all be safely converted to use a pattern along the lines of:
{{{#!php
<?php
date_format( date_create( 'time phrase or timestamp' ), $format )
}}}

Other references:
* [https://www.php.net/manual/en/function.strftime.php PHP Manual: strftime()] (for the old format string characters)
* [https://www.php.net/manual/en/datetime.format.php PHP Manual: DateTime::format()] (for the new format string characters)
* [https://www.php.net/manual/en/datetime.construct.php PHP Manual: DateTime::__construct()] (see Example 2 for a Unix timestamp code sample)

Props jrf, SergeyBiryukov.
Fixes #53897.

git-svn-id: https://develop.svn.wordpress.org/trunk@51587 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 19:08:09 +00:00
Sergey Biryukov
fff4242f1a Code Modernization: Rename the readonly() function to wp_readonly().
Since PHP 8.1, `readonly` is a reserved keyword and cannot be used as a function name.

In order to avoid PHP parser errors, the `readonly()` function was extracted to a separate file and is now only included conditionally on PHP < 8.1.

This commit also:
* Moves the tests for the `__checked_selected_helper()` function and all the related functions to their own file.
* Switches to named data providers. This makes the output when using the `--testdox` option more descriptive and is helpful when trying to debug which data set from a data provider failed the test.
* Improves the tests in question to make them feature-complete and expand test coverage.

Props jrf, ayeshrajans, haosun, knutsp, swissspidy, SergeyBiryukov.
Fixes #53858.

git-svn-id: https://develop.svn.wordpress.org/trunk@51586 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 17:19:21 +00:00
Sergey Biryukov
385025b0ba Build/Test Tools: Declare two TestCase classes as abstract.
TestCases which are intended to be extended and not run directly, should be `abstract`.

Follow-up to [763/tests], [30277].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51585 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 14:51:05 +00:00
Sergey Biryukov
9e07a480c5 Build/Test Tools: Remove Unicode character from PHPUnit version check message.
Not all CLI tools can handle Unicode characters or non-system specific line endings well, so this type of CLI messaging should always be written with the optimal cross-platform, cross-CLI tool end-user experience in mind.

Follow-up to [51581].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51584 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 13:04:38 +00:00
Sergey Biryukov
40bbe55b8e Build/Test Tools: Add schema reference to PHPUnit config files.
The current config files validate against the PHPUnit XSD schema for config files for PHPUnit 5.7 – 9.2.

The schema was changed in PHPUnit 9.3, and the `filter` and `logging` settings were deprecated in favor of `coverage` and a different format for `logging`.

This commit explicitly sets the schema against which the files currently validate, for clarity.

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51583 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 12:52:58 +00:00
Sergey Biryukov
53f5eaddb4 Build/Test Tools: Fix message display in test bootstrap.
Any messages to the user which are echo-ed out in the test bootstrap will generally display on a command-line interface.

The *nix specific `"\n"` line ending will be ignored on Windows, making the messages less readable.

For new lines in CLI messages, `PHP_EOL` should be used instead.

This was already done in a few places in the script, but not consistently so. Fixed now.

Follow-up to [UT882], [UT890], [44723], [45020], [48592], [49535], [51560].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51581 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 14:45:08 +00:00
Sergey Biryukov
fa2c313224 Tests: Use more appropriate assertions in get_themes() tests.
This replaces instances of `assertTrue( is_dir( ... ) )` with `assertDirectoryExists()` to use native PHPUnit functionality.

The `assertDirectoryExists()` method was introduced in PHPUnit 5.6. As the minimum supported PHPUnit version has been raised to PHPUnit 5.7.21, it can now be used.

Follow-up to [51543], [51574], [51579].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51580 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 14:18:31 +00:00
Sergey Biryukov
213bbf76ed Tests: Use more appropriate assertions in get_themes() tests.
This replaces instances of `assertTrue( is_file( ... ) )` followed by `assertTrue( is_readable( ... ) )` with `assertFileIsReadable()` to use native PHPUnit functionality.

The `assertFileIsReadable()` method was introduced in PHPUnit 5.6. As the minimum supported PHPUnit version has been raised to PHPUnit 5.7.21, it can now be used.

Follow-up to [51543], [51574].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51579 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 14:15:42 +00:00
Sergey Biryukov
14c6bcda56 Tests: Remove redundant @requires tags.
As the minimum supported PHPUnit version has been upped to PHPUnit 5.7.21, these `@requires` tags are now redundant.

Follow-up to [51226], [51234], [51559-51576].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51577 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:56:24 +00:00
Sergey Biryukov
f41d9545f9 Tests: Replace expectException() for PHP native errors with calls to the dedicated PHPUnit 8.4+ methods.
The old manner of testing these is soft deprecated as of PHPUnit 8.4, hard deprecated as of PHPUnit 9.0 and will be removed in PHPUnit 10.0.

Most calls like this were already replaced in [51563], however, this particular one could not be changed yet due to the mismatch between the PHPUnit version and the PHP version on which the tests were being run. This is fixed now.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.4.3/ChangeLog-8.4.md#840---2019-10-04
* https://github.com/sebastianbergmann/phpunit/issues/3775

Follow-up to [51559-51575].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51576 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:52:05 +00:00
Sergey Biryukov
36c997c4b2 Build/Test Tools: Remove the copied-in PHPUnit 9.x MockObject files.
As the version constraints for PHPUnit now allow the tests to be run on PHPUnit 8.x and 9.x, these files are no longer needed.

Follow-up to [48957], [49037], [51544], [51559-51574].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51575 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:44:00 +00:00
Sergey Biryukov
8def694fe4 Build/Test Tools: Loosen the PHPUnit restriction.
**composer.json**:

Remove the PHPUnit dependency in favor of allowing the PHPUnit Polyfills library to manage the supported PHPUnit version. This automatically now widens the supported PHPUnit versions to 5.7.21 to 9.5.8 (current).

Letting the PHPUnit Polyfills handle the version constraints for PHPUnit prevents potential version conflicts in the future, as well as allows WordPress to benefit straight away when a new PHPUnit version would be released and the PHPUnit Polyfills package adds support for that PHPUnit version.

**Test Bootstrap**

Update the supported version number for PHPUnit 5.x, as the minimum PHPUnit 5.x version supported by the PHPUnit Polyfills is PHPUnit 5.7.21, and remove the PHPUnit maximum.

**.gitignore and svn:ignore:**

Add the PHPUnit cache file to the list of files to be ignored.

Since PHPUnit 8, PHPUnit has a built-in caching feature which creates a `.phpunit.result.cache` file. This file should not be committed.

Follow-up to [40536], [40853], [44701], [51559-51573].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51574 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:41:53 +00:00
Sergey Biryukov
aae784273f Build/Test Tools: Remove SpeedTrapListener.
Now that the tests can run PHPUnit cross-version and Composer will be used to install the test suite in CI, we could switch out the local copies of the [https://github.com/johnkary/phpunit-speedtrap PHPUnit speedtrap] package in favor of using the Composer package, which would prevent us having to make the WP local copies of the class compatible with later PHPUnit versions.

The SpeedTrap test listener was introduced to identify slow tests and take action on these to make them faster.

In practice, however, no notable action was ever taken based on the output of the test listener in all the years it was in place.

With that in mind, it was decided to remove the SpeedTrap test listeners without replacement.

If – at a future date – contributors would want to take action to speed up slow tests anyway, they can:
* Either add the package to their local install and use the output they receive locally to identify slow tests.
* Or use the PHPUnit native `@small` annotations in combination with the PHPUnit `PHP_Invoker` package as described in the PHPUnit documentation to [https://phpunit.readthedocs.io/en/stable/risky-tests.html#test-execution-timeout run tests with time limits].

Follow-up to [35214], [35226], [35767], [44701], [51559-51572].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51573 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:14:39 +00:00
Sergey Biryukov
e8ea993ce7 Build/Test Tools: Handle removal of TestCase::getAnnotations().
The PHPUnit native `TestCase::getAnnotations()` method is used to check for WP flavored deprecation notices, however, this method was not covered by the backward compatibility promise for PHPUnit (and was annotated as excluded).

The method has been removed as part of an internal refactor in commit [68582043e1 sebastianbergmann/phpunit@6858204], which is included in PHPUnit 9.5.0.

For now, a workaround is put in place, but it is recommended that the WP `expectDeprecated()` method should be reevaluated in a future iteration.

Follow-up to [51559-51571].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51572 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:00:52 +00:00
Sergey Biryukov
60dcae95ea Tests: Fix tests failing due to assertContains() using strict checking.
Since PHPUnit 8.0.2, the `assertContains()` method, when checking whether a value exists in an array, will do a strict type comparison of the values.

This caused a couple of tests to fail. Using the correct data type in the test fixes that.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* https://github.com/sebastianbergmann/phpunit/issues/3511
* 6205f33595

Follow-up to [51559-51570].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51571 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 10:51:59 +00:00
Sergey Biryukov
fcd4aa4700 Build/Test Tools: Alias the Getopt class conditionally, as the class no longer exists in PHPUnit 9.x.
Most of the aliasing in this `compat.php` file is redundant as PHPUnit 5.7.21+ contains a forward compatibility layer for these classes anyway (= PHPUnit provides both the namespaced and underscore named versions of these classes in PHPUnit 5.7.21+).

All the same, the file and the aliases are left in place for the time being, as plugins/themes using the WP test suite as the basis for their integration tests may rely on it, though WP itself should not really need it anymore, save for maybe one or two classes.

Follow-up to [51559-51569].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51570 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 10:46:54 +00:00
Sergey Biryukov
22060f3b06 Tests: Remove use of assertArraySubset() in Test_WP_Widget_Media::test_constructor().
The `assertArraySubset()` method has been deprecated in PHPUnit 8 and removed in PHPUnit 9.

This replaces the assertions with looping through the array and testing both the key and the value individually.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#800---2019-02-01
* https://github.com/sebastianbergmann/phpunit/issues/3494

Note: There is a polyfill package available for the removed assertion: `dms/phpunit-arraysubset-asserts`, but as the assertion was only used in this one test method, adding this seems redundant.

Follow-up to [51559-51568].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51569 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 10:40:44 +00:00