wordpress-develop/tests/phpunit/tests
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
..
actions Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
admin Media: Check the return type of _get_cron_array() in WP_Media_List_Table::prepare_items(). 2021-08-19 12:43:03 +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 Blocks: Add support for variations in block.json` file 2021-08-11 09:06:31 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
comment Tests: Fix tests failing due to assertContains() using strict checking. 2021-08-07 10:51:59 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
dependencies Tests: Replace expectException() for PHP native errors with calls to the dedicated PHPUnit 8.4+ methods. 2021-08-07 11:52:05 +00:00
editor Tests: Simplify @covers tags in editor/wpEditors.php using @coversDefaultClass annotation. 2021-02-13 13:45:23 +00:00
error-protection Tests: Correct some newly introduced @covers tags. 2021-03-16 18:44:40 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +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: Use a better return type check for parse_url() in do_enclose() tests. 2021-08-17 00:27:38 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +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 Blocks: Add support for variations in block.json` file 2021-08-11 09:06:31 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
pomo Tests: Move loading the PO class to set_up_before_class(). 2021-08-17 20:01:15 +00:00
post Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +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 Tests: Remove redundant @requires tags. 2021-08-07 11:56:24 +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: Use more appropriate assertions in various tests. 2021-07-11 12:41:48 +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 Tests: Use assertSame() in some newly introduced tests. 2021-06-07 11:16:29 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +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 Code Modernization: Check the return type of _get_cron_array() in wp_schedule_event(). 2021-08-16 15:22:38 +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 Blocks: Add support for variations in block.json` file 2021-08-11 09:06:31 +00:00
https-detection.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
https-migration.php Tests: Use assertSame() in some newly introduced tests. 2021-02-10 13:24:24 +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 Code Modernization: Replace strftime() and gmstrftime() usage in unit tests. 2021-08-09 19:08:09 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
rewrite.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
robots.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +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 Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
walker.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
widgets.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
wp.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00