wordpress-develop/tests/phpunit/tests
Tonya Mork 97790af164 Options, Meta APIs: Fix "passing null to non-nullable" deprecations to (get|add|update|delete)_option().
In all four of the `get_option()`, `add_option()`, `update_option()` and `delete_option()` functions, the `$option` parameter (i.e. the option name) is passed to the PHP native `trim()` function without prior input validation.

In PHP 8.1, this could lead to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` for each of these functions.

`trim()`:

- expects a text string and is only useful when ''passed'' a text string as no other variable type can contain whitespace.
- will always return a `string`, which means that in practice for any non-string values passed, it would effectively function as a type cast to string.

This commit:
- Adds a check to verify the `$option` name is a scalar before processing it with `trim()`.
- The "type cast" behavior is maintained.
- If the given `$option` name is not a scalar, such as `null`, the fix prevents the PHP 8.1 deprecation notice.
- Tests are added for valid but undesired option names to safeguard against regressions.

This issue is already covered by:
- the existing `Tests_Option_Option::test_bad_option_names()` test group.
- the new `test_valid_but_undesired_option_names()` tests.

Follow-up to [13858], [22633], [23510], [25002], [51817].

Props jrf, hellofromTonya, pbearne.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51818 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 22:18:36 +00:00
..
actions Tests: Add missing @covers tags for actions' tests. 2021-08-31 17:22:32 +00:00
admin Tests: Fix "null to non-nullable" deprecation notice in Tests_Admin_IncludesPlugin::test_get_plugin_files_folder(). 2021-09-10 17:26:42 +00:00
ajax Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
attachment Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
blocks Editor: Ensure block attribute serialization in PHP matches the JavaScript equivalent. 2021-08-26 19:09:16 +00:00
bookmark Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
canonical Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +00:00
category Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
comment Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
cron Code Modernization: Add input validation to _set_cron_array(). 2021-08-30 15:19:38 +00:00
customize Tests: Remove use of assertArraySubset() in Test_WP_Widget_Media::test_constructor(). 2021-08-07 10:40:44 +00:00
date Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
db Tests: Add tests for wpdb::_real_escape(). 2021-09-10 16:29:24 +00:00
dependencies Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
editor Tests: Rename classes in phpunit/tests/editor/ per the naming conventions. 2021-08-20 16:11:04 +00:00
error-protection Tests: Rename classes in phpunit/tests/error-protection/ per the naming conventions. 2021-08-21 15:32:53 +00:00
external-http Tests: Add missing @covers tags for files in phpunit/tests/external-http/. 2021-02-11 20:53:51 +00:00
feed Tests: Rename classes in phpunit/tests/feed/ per the naming conventions. 2021-08-22 10:07:17 +00:00
filesystem Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
formatting Code Modernization: Correct handling of null in wp_parse_str(). 2021-08-16 22:16:32 +00:00
functions Tests: Add more invalid IP test cases and @covers to Tests_Functions_Anonymization. 2021-09-09 22:43:49 +00:00
general Code Modernization: Rename the readonly() function to wp_readonly(). 2021-08-09 17:19:21 +00:00
hooks Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
http Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
image Media: apply the wp_editor_set_quality filter not only when loading an image in the editor but also when saving an converted image, after the mime-type of the output image has changed. 2021-08-31 18:57:09 +00:00
import Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
includes Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
l10n Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
link Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
load Multisite: Log error/warnings/notices from ms-files.php. 2021-07-06 20:20:51 +00:00
media Build/Test Tools: Replace assertInternalType() usage in unit tests. 2021-07-05 17:21:53 +00:00
menu Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
meta Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
multisite Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +00:00
oembed Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +00:00
option Options, Meta APIs: Fix "passing null to non-nullable" deprecations to (get|add|update|delete)_option(). 2021-09-15 22:18:36 +00:00
pomo Tests: Move loading the PO class to set_up_before_class(). 2021-08-17 20:01:15 +00:00
post Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
privacy Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
query Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
rest-api Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
rewrite Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
sitemaps Tests: Rename classes in phpunit/tests/sitemaps/ per the naming conventions. 2021-07-26 19:09:41 +00:00
taxonomy Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
term Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
theme Blocks: Add support for variations in block.json` file 2021-08-11 09:06:31 +00:00
url Build/Test Tools: Standardise the name, signature, and usage of the wpSetUpBeforeClass() method that's used in test classes. 2020-11-15 13:59:32 +00:00
user Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
widgets Tests: Remove use of assertArraySubset() in Test_WP_Widget_Media::test_constructor(). 2021-08-07 10:40:44 +00:00
wp Code Modernization: Check the return type of parse_url() in WP::parse_request(). 2021-08-16 20:16:13 +00:00
xmlrpc Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +00:00
actions.php Tests: Add missing @covers tags for actions' tests. 2021-08-31 17:22:32 +00:00
adminbar.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
auth.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
avatar.php Tests: Replace assertRegExp() with assertMatchesRegularExpression(). 2021-08-06 21:52:06 +00:00
basic.php Build/Test Tools: Fix tests after [50185]. 2021-02-05 03:36:26 +00:00
block-template-utils.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
block-template.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
cache.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
canonical.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
category.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
comment-submission.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
comment.php Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +00:00
compat.php Code Modernization: Silence the deprecation warning for missing return type in phpunit/tests/compat.php. 2021-08-10 17:34:30 +00:00
cron.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
db.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
dbdelta.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
dependencies.php Tests: Use more appropriate assertions in various tests. 2021-07-10 11:15:44 +00:00
file.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
filters.php Tests: Use more appropriate assertions in various tests. 2021-07-11 12:41:48 +00:00
functions.php 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. 2021-08-24 20:50:21 +00:00
https-detection.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
https-migration.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
kses.php Tests: Use more appropriate assertions in various tests. 2021-07-10 11:15:44 +00:00
l10n.php Tests: Replace assertContains() with assertStringContainsString() when used with strings. 2021-07-19 14:00:11 +00:00
link.php Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +00:00
locale.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
mail.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
media.php Media: Fix $content parameter default value in img_caption_shortcode(). 2021-09-15 19:05:20 +00:00
meta.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
multisite.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
pluggable.php Tests: Use more appropriate assertions in various tests. 2021-07-12 10:35:44 +00:00
post.php Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +00:00
query.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
rest-api.php REST API: Remove trailing slashes when preloading requests and add unit tests for it. 2021-08-20 23:43:21 +00:00
rewrite.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
robots.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
shortcode.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
site-health.php Build/Test Tools: Standardise the name, signature, and usage of the wpSetUpBeforeClass() method that's used in test classes. 2020-11-15 13:59:32 +00:00
taxonomy.php Tests: Use more appropriate assertions in various tests. 2021-07-15 14:44:22 +00:00
template.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
term.php Tests: Use more appropriate assertions in various tests. 2021-07-18 14:10:24 +00:00
theme.php Tests: Use more appropriate assertions in get_themes() tests. 2021-08-07 14:18:31 +00:00
upload.php Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +00:00
url.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
user.php Users: Introduce a meta_input argument for wp_insert_user(). 2021-09-07 21:30:07 +00:00
walker.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
widgets.php Widgets: Revert [51705]. 2021-09-09 21:39:39 +00:00
wp.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00