wordpress-develop/tests/phpunit/tests
Ian Dunn cac678f807 Multisite: Cache absolute dirsize paths to avoid PHP 8 fatal.
r49212 greatly improved the performance of `get_dirsize()`, but also changed the structure of the data stored in the `dirsize_cache` transient. It stored relative paths instead of absolute ones, and also removed the unnecessary `size` array.

That difference in data structures led to a fatal error in the following environment:

* PHP 8
* Multisite
* A custom `WP_CONTENT_DIR` which is not a child of WP's `ABSPATH` folder (e.g., [https://roots.io/bedrock/ Bedrock])
* The `upload_space_check_disabled` option set to `0`

After upgrading to WP 5.6, the `dirsize_cache` transient still had data in the old format. When `wp-admin.php/index.php` was visited, `get_space_used()` received an `array` instead of an `int`, and tried to divide it by another `int`. PHP 7 would silently cast the arguments to match data types, but [https://wiki.php.net/rfc/arithmetic_operator_type_checks PHP 8 throws a fatal error]: 

`Uncaught TypeError: Unsupported operand types: array / int`

`recurse_dirsize()` was using `ABSPATH` to convert the absolute paths to relative ones, but some upload locations are not located under `ABSPATH`. In those cases, `$directory` and `$cache_path` were identical, and that triggered the early return of the old `array`, instead of the expected `int`. 

In order to avoid that, this commit restores the absolute paths, but without the `size` array. It also adds a type check when returning cached values. Using absolute paths without `size` has the result of overwriting the old data, so that it matches the new format. The type check and upgrade routine are additional safety measures.

Props peterwilsoncc, janthiel, helen, hellofromtonya, francina, pbiron.
Fixes #51913. See #19879.



git-svn-id: https://develop.svn.wordpress.org/trunk@49744 602fd350-edb4-49c9-b593-d223f7449a82
2020-12-03 20:37:43 +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 Tests: Ignore EOL differences in WP_List_Table::get_bulk_items() test for optgroups. 2020-11-24 20:41:13 +00:00
ajax Build/Test Tools: Remove unused posts from AJAX test setUp(). 2020-11-25 04:09:41 +00:00
attachment 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
blocks Editor: Remove render_block hooks from WP_Block 2020-11-25 01:18:25 +00:00
bookmark Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate. 2020-09-04 07:01:00 +00:00
canonical Permalinks: Prevent attachment pages 404ing following [49563]. 2020-11-17 03:27:07 +00:00
category Menus: In Walker_Nav_Menu, Walker_Category, and Walker_Page, properly output link attributes having a legitimate "empty" value, for example an HTML data attribute with a value of zero (0). 2019-10-06 15:04:18 +00:00
comment 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
customize Customize: Ensure multiple CSS classes are passed to nav_menu_link_attributes as an array 2020-11-17 04:29:02 +00:00
date Build/Test Tools: Misc test enhancements. 2020-11-15 17:17:55 +00:00
db Tests: Use consistent trailing punctuation in markTestSkipped() messages. 2020-09-21 14:05:23 +00:00
dependencies Build/Test Tools: Improve the reliability of the test that ensures correct dependency order when inline scripts are used. 2020-11-14 17:20:57 +00:00
editor Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate. 2020-09-04 07:01:00 +00:00
error-protection Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
external-http Docs: Improve inline comments per the documentation standards. 2020-01-29 00:43:23 +00:00
feed 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
filesystem Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
formatting Tests: Test that sanitize_title_with_dashes() strips HTML tags. 2020-11-27 12:50:11 +00:00
functions 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
general General: Introduce the ability to merge multiple WP_Error objects into one another, and to store more than one item of data for an error. 2020-10-09 22:20:50 +00:00
hooks Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate. 2020-09-04 07:01:00 +00:00
http Code Modernization: Use explicit visibility for class property declarations. 2020-10-17 16:24:35 +00:00
image Media: Restore the ability of WP_Image_Editor_Imagick->save() to create a missing directory when needed. 2020-11-09 13:16:54 +00:00
import Tests: Use consistent trailing punctuation in fail() messages. 2020-09-22 12:32:39 +00:00
includes Tests: Consistently use the expectException() method instead of the older @expectedException annotation. 2020-09-18 13:22:22 +00:00
l10n I18N: Avoid PHP notices for relative URLs in load_script_textdomain(). 2020-11-17 20:50:21 +00:00
link 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
load Bootstrap: Enhance core's memory limit handling. 2016-07-08 14:36:37 +00:00
media Coding Standards: Upgrade WPCS to 1.0.0 2018-08-17 01:50:26 +00:00
menu General: Remove noreferrer from wp_targeted_link_rel() and other uses. 2020-10-19 23:37:53 +00:00
meta 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
multisite Multisite: Cache absolute dirsize paths to avoid PHP 8 fatal. 2020-12-03 20:37:43 +00:00
oembed 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
option General: Replace older-style PHP type conversion functions with type casts. 2020-10-08 21:13:57 +00:00
pomo Tests: Simplify PluralFormsTest::test_exceptions(). 2020-09-18 14:11:11 +00:00
post REST API: Pass the previous state of the post as a parameter to the wp_after_insert_post hook. 2020-12-01 20:45:43 +00:00
privacy 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
query 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
rest-api App Passwords: Unify availability language. 2020-11-16 22:40:11 +00:00
rewrite 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
sitemaps 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 Tests: Add missing parent::setUp() calls to all test classes. 2019-01-14 04:54:01 +00:00
term 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
theme 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
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 Built/Test Tools: Switch to a data provider for the default user role and capability tests. 2020-11-15 14:57:39 +00:00
widgets General: Remove noreferrer from wp_targeted_link_rel() and other uses. 2020-10-19 23:37:53 +00:00
xmlrpc 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
actions.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
adminbar.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
auth.php App Passwords: Unify availability language. 2020-11-16 22:40:11 +00:00
avatar.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
basic.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
cache.php Code Modernization: Use explicit visibility for class property declarations. 2020-10-17 16:24:35 +00:00
canonical.php Canonical: Support multiple post types in redirect_guess_404_permalink(). 2020-10-18 23:21:03 +00:00
category.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
comment-submission.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
comment.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
compat.php Tests: Consistently use the expectException() method instead of the older @expectedException annotation. 2020-09-18 13:22:22 +00:00
cron.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
db.php Coding Standards: Replace alias PHP functions with the canonical names. 2020-10-18 17:25:10 +00:00
dbdelta.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
dependencies.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
file.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
filters.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
functions.php Build/Test Tools: Remove PHP >= 5.3 check. 2020-11-09 19:40:41 +00:00
kses.php Build/Test Tools: Use dataProviders for some kses tests. 2020-11-25 04:49:04 +00:00
l10n.php Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate. 2020-09-04 07:01:00 +00:00
link.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
locale.php Tests: Fix the failure in test_get_weekday_undefined_index() on PHP 8. 2020-09-18 10:56:27 +00:00
mail.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
media.php Permalinks: Prevent attachment pages 404ing following [49563]. 2020-11-17 03:27:07 +00:00
meta.php Tests: Replace a few instances of assertNotEquals() with assertNotFalse(). 2020-09-07 04:11:54 +00:00
multisite.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
pluggable.php Cache API: Introduce wp_cache_get_multi(). 2020-06-09 19:45:27 +00:00
post.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
query.php Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate. 2020-09-04 07:01:00 +00:00
rest-api.php REST API: Add support for the oneOf and anyOf keywords. 2020-10-20 18:22:39 +00:00
rewrite.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
shortcode.php Tests: Update third-party video URLs in unit tests with more permanent videos. 2020-10-10 01:37:18 +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 Taxonomy: Revert Light-weight/partial term counts. 2020-10-30 04:57:16 +00:00
template.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
term.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
theme.php Bundled Themes: Make Twenty Twenty-One the default theme. 2020-10-20 02:02:37 +00:00
upload.php Code Modernization: Use explicit visibility for class property declarations. 2020-10-17 16:24:35 +00:00
url.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
user.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
walker.php Code Modernization: Use explicit visibility for class property declarations. 2020-10-17 16:24:35 +00:00
widgets.php Widgets: Introduce before_sidebar and after_sidebar arguments for register_sidebar(). 2020-10-19 15:38:11 +00:00
wp.php Coding Standards: Fix the remaining issues in /tests. 2019-07-08 00:55:20 +00:00