wordpress-develop/tests/phpunit/tests/date
Sergey Biryukov 85106c694d Code Modernization: Fix null to non-nullable deprecations in wp_xmlrpc_server::_insert_post().
The `wp_xmlrpc_server::_insert_post()` method creates a new post via `wp_insert_post()` or updates an existing one via `wp_update_post()`, which subsequently calls `wp_insert_post()`. However, the default/fallback values used in the function were not in line with the default/fallback values used in the `wp_insert_post()` function.

The `wp_insert_post()` function does a `wp_parse_args()` (array merge) of the received arguments with the defaults. If any of the received arguments are `null`, this would overwrite the default value, as seen in [https://3v4l.org/bfVlv array_merge() example], and lead to "passing null to non-nullable" deprecation notices on PHP 8.1 for certain arguments.

Unfortunately, the conditional logic within the `wp_xmlrpc_server::_insert_post()` function itself often uses an `isset()` to trigger certain code blocks, so syncing the defaults with those used in the `wp_insert_post()` function was not an option.

This commit:
* Updates the default/fallback values in the `$defaults` array only for those values where this would not lead to a change in the behavior of the function.
* Adds a safeguard function, filtering out all remaining `null` values from the `$post_data` array before it is passed on to the `wp_insert_post()` or `wp_update_post()` functions. Removing those values is safe as this means that these array keys will now:
 * either be set to the default/fallback value as defined in `wp_insert_post()`.
 * or not be set and for those values which don't have a default/fallback value in `wp_insert_post()`, the function does an `! empty()` or `isset()` check anyway and those array keys not being defined means that the result of those checks will remain the same.

Includes
* Removing a couple of conditions which are now redundant.
* Removing an `expectDeprecation()` in the `Tests_Date_XMLRPC` test class, which is now no longer needed.

Fixes various errors along the lines of:
{{{
36) Tests_XMLRPC_wp_newPost::test_no_content
json_decode(): Passing null to parameter #1 ($json) of type string is deprecated

/var/www/src/wp-includes/kses.php:2074
/var/www/src/wp-includes/class-wp-hook.php:307
/var/www/src/wp-includes/plugin.php:205
/var/www/src/wp-includes/post.php:2835
/var/www/src/wp-includes/post.php:2720
/var/www/src/wp-includes/post.php:4066
/var/www/src/wp-includes/class-wp-xmlrpc-server.php:1683
/var/www/src/wp-includes/class-wp-xmlrpc-server.php:1347
/var/www/tests/phpunit/tests/xmlrpc/wp/newPost.php:25
/var/www/vendor/bin/phpunit:123
}}}

Follow-up to [1563], [4793], [7900], [16824], [19848], [19873], [20632], [40677], [51968], [54320].

Props jrf.
See #55656.

git-svn-id: https://develop.svn.wordpress.org/trunk@54321 602fd350-edb4-49c9-b593-d223f7449a82
2022-09-27 02:16:28 +00:00
..
currentDatetime.php Date/Time: Add a unit test for the return type of current_datetime(). 2022-01-21 05:58:13 +00:00
currentTime.php Tests: Add tests with deprecated timezone strings. 2022-09-19 23:51:20 +00:00
dateI18n.php Tests: Add tests with deprecated timezone strings. 2022-09-19 23:51:20 +00:00
getCommentDate.php Tests: Rename some classes in phpunit/tests/date/ per the naming conventions. 2021-02-11 21:20:41 +00:00
getFeedBuildDate.php Tests: Replace the timezone used in date/time tests. 2022-09-19 21:18:59 +00:00
getPermalink.php Tests: Reset timezone-related options if the tests change them. 2022-09-19 17:43:55 +00:00
getPostTime.php Tests: Replace the timezone used in date/time tests. 2022-09-19 21:18:59 +00:00
getTheDate.php Tests: Rename some classes in phpunit/tests/date/ per the naming conventions. 2021-02-11 21:20:41 +00:00
getTheModifiedDate.php Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
maybeDeclineDate.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
mysql2date.php Tests: Add tests with deprecated timezone strings. 2022-09-19 23:51:20 +00:00
query.php Tests: Replace the timezone used in date/time tests. 2022-09-19 21:18:59 +00:00
theDate.php Coding Standards: Add visibility to methods in tests/phpunit/tests/. 2021-11-04 15:22:47 +00:00
wpDate.php Date/Time: Increase test coverage of wp_date(). 2022-08-01 22:48:42 +00:00
wpTimezone.php Tests: Add tests with deprecated timezone strings. 2022-09-19 23:51:20 +00:00
xmlrpc.php Code Modernization: Fix null to non-nullable deprecations in wp_xmlrpc_server::_insert_post(). 2022-09-27 02:16:28 +00:00