Repository navigation
Tests: define UPLOADS constant for php unit. - #13065
OlegApanovich wants to merge 14 commits into
Conversation
Points the test suite at a dedicated wp-content/test-suite-uploads directory instead of the real wp-content/uploads, so test runs don't write to actual site content. The directory wp-content/test-suite-uploads is deleted once before new tests run. Adds an _upload_get_url() helper and updates tests that previously hardcoded wp-content/uploads. Trac ticket: https://core.trac.wordpress.org/ticket/63532
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…m:OlegApanovich/wordpress-develop into 63532-define-uploads-constant-for-phpunit
lancewillett
left a comment
There was a problem hiding this comment.
Please preserve the option-based upload tests: defining UPLOADS globally makes the relative-path, absolute-path and custom-URL cases exercise the override instead. Their original behavior needs to remain covered.
The new lock also fails when wp-content/uploads does not exist: touch() returns false, leaving deletion enabled without a marker. Please ensure successful lock creation before relying on it. A date hash also does not distinguish concurrent runs.
Finally, please run the ms-files group explicitly. Its main-site rewriting scenario ignores UPLOADS in production, so changing its expectation to test-suite-uploads does not match that path. The default multisite configuration excludes this group.
AI review · gpt-6
There was a problem hiding this comment.
🟡 Changes recommended
Legacy multisite uploads remain outside the test directory and conflict with new assertions, while lock handling and filesystem initialization can delete fixtures or abort bootstrap.
4 open issues
What changed in this PR
This PR moves PHPUnit uploads to a dedicated test directory to keep test runs from writing to normal site uploads.
Changes:
- Defines
UPLOADSand adds lock-based cleanup during test bootstrap. - Adds
_upload_get_url()and updates upload-related fixtures and assertions. - Excludes the test uploads directory from version control.
| File | Description |
|---|---|
tests/phpunit/tests/upload.php |
Updates upload path and URL expectations. |
tests/phpunit/tests/speculative-loading/wpGetSpeculationRules.php |
Uses UPLOADS in exclusion patterns. |
tests/phpunit/tests/multisite/site.php |
Updates site-switching upload expectations. |
tests/phpunit/tests/multisite/msFilesRewriting.php |
Changes legacy multisite main-site expectations. |
tests/phpunit/tests/media/previousImageLink.php |
Uses the helper for previous-image URLs. |
tests/phpunit/tests/media/nextImageLink.php |
Uses the helper for next-image URLs. |
tests/phpunit/tests/media/getPreviousImageLink.php |
Updates expected previous-image markup. |
tests/phpunit/tests/media/getPostGalleries.php |
Updates gallery URLs and expected output. |
tests/phpunit/tests/media/getNextImageLink.php |
Updates expected next-image markup. |
tests/phpunit/tests/media/getAdjacentImageLink.php |
Updates expected adjacent-image markup. |
tests/phpunit/tests/media.php |
Replaces hardcoded media upload URLs. |
tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php |
Updates the expected font upload path. |
tests/phpunit/tests/fonts/font-library/wpFontsDir.php |
Derives font expectations from the switched site's uploads. |
tests/phpunit/includes/functions.php |
Adds the shared upload URL helper. |
tests/phpunit/includes/bootstrap.php |
Configures test uploads and startup cleanup. |
.gitignore |
Ignores the dedicated test uploads directory. |
Review effort: Balanced
Replaces the date-hashed lock file in wp-content/uploads with a WP_TESTS_UPLOADS_RUN_ID environment variable, which is inherited by @runInSeparateProcess child processes. This prevents isolated tests from deleting the test uploads dir again when a run crosses UTC midnight or when wp-content/uploads does not exist, and no longer writes a lock file into real site content. Trac ticket: https://core.trac.wordpress.org/ticket/63532
WP_Filesystem() may select the FTP or SSH transport based on FS_METHOD or checkout ownership, then fail to connect without credentials, which could abort the bootstrap instead of cleaning the directory. The test uploads dir is always local, so use a WP_Filesystem_Direct instance directly. This also avoids setting the global $wp_filesystem for the whole test run. Trac ticket: https://core.trac.wordpress.org/ticket/63532
Defining UPLOADS globally made the relative path, absolute path and custom URL tests exercise the UPLOADS override instead of the upload_path and upload_url_path options. Moves these tests, unchanged from trunk, into a new Tests_Upload_UploadDirOptions class that runs in separate processes. The class sets WP_TESTS_SKIP_UPLOADS_CONSTANT so that bootstrap.php skips defining UPLOADS in those processes. Trac ticket: https://core.trac.wordpress.org/ticket/63532
With ms_files_rewriting enabled, _wp_upload_dir() ignores UPLOADS on the main site and uses UPLOADBLOGSDIR for subsites, so this group still wrote to wp-content/uploads and wp-content/blogs.dir. The main site assertions only passed because wp_upload_dir() returned a value cached before rewriting was enabled. Points UPLOADBLOGSDIR and the main site upload_path option at the test uploads dir, refreshes the upload dir cache, and updates the subsite expectations to use UPLOADBLOGSDIR. Trac ticket: https://core.trac.wordpress.org/ticket/63532
…ds-constant-for-phpunit # Conflicts: # tests/phpunit/tests/multisite/msFilesRewriting.php
…m:OlegApanovich/wordpress-develop into 63532-define-uploads-constant-for-phpunit
The previous change built the expected font dir from the switched-to
site's own upload dir, which mirrors _wp_filter_font_directory() and
no longer verifies that subsite fonts live under /sites/{$blog_id}.
Restores the trunk expectations and only updates the URLs, which are
built from the switched-to site's siteurl when UPLOADS is defined.
Trac ticket: https://core.trac.wordpress.org/ticket/63532
There was a problem hiding this comment.
🟡 Changes recommended
The inherited setup creates real upload directories before options are changed, so this path-only test class needs an upload-scan override to preserve filesystem isolation.
1 open issue
4 resolved since last review
Review effort: Balanced
The inherited scan_user_uploads() calls wp_upload_dir(), which creates the real wp-content/uploads/YYYY/MM directory in each isolated process because UPLOADS is not defined there. These tests only inspect paths, so there are no upload files to track.
@lancewillett
Could you please take another look? |
There was a problem hiding this comment.
🔵 Needs a closer look
Unavailable test dependencies prevented runtime verification of the upload-option tests’ parent/child class-setup lifecycle and once-per-run cleanup across supported PHPUnit versions.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
The dedicated upload directory and the option/ms-files fixtures are useful. Please remove the recursive startup deletion and its WP_TESTS_UPLOADS_RUN_ID bookkeeping unless there is an existing failing case that requires them. The current runs establish compatibility, but do not show a consumer that needs the directory purged. Keep the upload-path override and separate-process option coverage; no additional synthetic test or locking mechanism is needed.
The isolated option tests pass in single-site and multisite, and the explicit ms-files tests pass. The broader affected selection has the same font-face test error on baseline and patch. This request concerns cleanup necessity, not a demonstrated regression.
AI review · gpt-6
lancewillett
left a comment
There was a problem hiding this comment.
I investigated the startup cleanup further and can now demonstrate its benefit. This supersedes my request to remove it.
I stopped an existing media test immediately after its class fixture created the image files, then reran the unchanged tests from the same saved files. The dedicated UPLOADS path stayed enabled; only startup deletion was toggled.
In both single-site and multisite, Tests_Media::test_wp_get_attachment_image_should_use_wp_get_attachment_metadata:
- passes with a clean directory and deletion disabled;
- fails with interrupted-run leftovers and deletion disabled (
test-image-large-1-150x150.jpginstead oftest-image-large-150x150.jpg); - passes with those same leftovers and deletion enabled.
This reproduces the filename-collision problem described in #63532 using real class fixtures. The full media selection also passes with cleanup in both modes: 368 tests / 1,193 assertions, with one existing skip. No test assertions were changed or new test methods added. The earlier isolated upload-option and explicit ms-files checks passed too; the broader font-face error reproduced on baseline and patch.
Startup cleanup therefore has demonstrated value for recovery after an interrupted run. This does not establish support for independently concurrent runs sharing the directory. Current-head CI is green.
AI review · gpt-6
Use `wp-content/test-suite-uploads` for test uploads and remove leftover files once at startup. This prevents interrupted runs from causing filename collisions in later media tests and keeps test files separate from normal uploads. Update upload URL expectations and run tests for the `upload_path` and `upload_url_path` options in separate processes without the `UPLOADS` constant. Developed in: #13065 Props mrdollar4444. Fixes #63532. git-svn-id: https://develop.svn.wordpress.org/trunk@65177 602fd350-edb4-49c9-b593-d223f7449a82
Use `wp-content/test-suite-uploads` for test uploads and remove leftover files once at startup. This prevents interrupted runs from causing filename collisions in later media tests and keeps test files separate from normal uploads. Update upload URL expectations and run tests for the `upload_path` and `upload_url_path` options in separate processes without the `UPLOADS` constant. Developed in: WordPress/wordpress-develop#13065 Props mrdollar4444. Fixes #63532. Built from https://develop.svn.wordpress.org/trunk@65177 git-svn-id: http://core.svn.wordpress.org/trunk@64326 1a063a9b-81f0-0310-95a4-ce76da25c4cd


Points the test suite at a dedicated wp-content/test-suite-uploads directory instead of the real wp-content/uploads, so test runs don't write to actual site content.
The directory wp-content/test-suite-uploads is deleted once before new tests run.
Adds an _upload_get_url() helper and updates tests that previously hardcoded wp-content/uploads.
Trac ticket: https://core.trac.wordpress.org/ticket/63532
Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): GPT-5.1
Used for: Only for simple, repetitive actions; all architectural decisions are mine alone.