Make WordPress Core

Opened 3 years ago

Closed 8 days ago

Last modified 8 days ago

#59788 closed enhancement (fixed)

test for wp_delete_file

Reported by: pbearne Owned by: lancewillett
Priority: normal Milestone: 7.2
Component: Filesystem API Version:
Severity: normal Keywords: has-unit-tests has-patch
Cc: Focuses: tests

Description


Change History (8)

This ticket was mentioned in ​PR #5611 on ​WordPress/wordpress-develop by ​@pbearne.


3 years ago
#1

  • Keywords has-patch has-unit-tests added

#2 @pbearne
3 years ago

  • Component General → Build/Test Tools
  • Keywords has-patch has-unit-tests removed

#3 @desrosj
2 years ago

  • Component Build/Test Tools → Filesystem API
  • Keywords has-unit-tests added
  • Milestone Awaiting Review → Future Release
  • Type defect (bug) → enhancement

Since this is about adding tests and not a general build or test tooling change, I'm reassigning it to the relevant component.

#4 @desrosj
6 months ago

  • Focuses tests added

Adding the tests focus, which is used to indicate a ticket is solely focused on adding tests.

This ticket was mentioned in ​PR #14890 on ​WordPress/wordpress-develop by ​bluefairydevelopment.


12 days ago
#5

  • Keywords has-patch added

Trunk's tests/phpunit/tests/functions/wpDeleteFile.php (added under #61590) already covers deleting a file, an empty path and a missing file. The wp_delete_file filter itself has no coverage. This adds the two filter cases:

  • test_wp_delete_file_does_not_delete_when_filter_returns_empty: the filter returns an empty path, wp_delete_file() returns false and the file stays.
  • test_wp_delete_file_deletes_the_filtered_path: the filter returns a different path, that path is deleted and the original is left alone.

This builds on pbearne's earlier PR #5611, which proposed the filter test before the #61590 tests landed. These are written against the current test file, using wp_tempnam() and cleaning up after themselves.

Verification: both tests pass, phpcs is clean, and when wp_delete_file() was changed to ignore the filter, exactly these two tests failed while the existing three still passed.

Props pbearne.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: comparing the ticket, the open PR and trunk, writing the tests, and checking that they fail when the filter is ignored. Submitted by Blue Fairy Development, who are responsible for the change.

#6 @bluefairydevelopment
12 days ago

PR covering the wp_delete_file filter (empty path and changed path): ​https://github.com/WordPress/wordpress-develop/pull/14890. The basic cases landed under #61590. Props pbearne for #5611.

#7 @lancewillett
8 days ago

  • Owner set to lancewillett
  • Resolution → fixed
  • Status new → closed

In 65087:

Tests: Cover filtering the path passed to wp_delete_file().

Verify that an empty filtered path prevents deletion and that a replacement path is deleted while the original file remains. Extend the existing basic deletion tests with both filter outcomes.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14890

Props bluefairydevelopment, pbearne.
Fixes #59788.

#8 @sabernhardt
8 days ago

  • Milestone Future Release → 7.2
Note: See TracTickets for help on using tickets.