Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#65651 new defect (bug)

Tests: Add PHPUnit tests for get_temp_dir()

Reported by: pbearne Owned by:
Priority: normal Milestone: Awaiting Review
Component: Upload Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: tests

Description

The get_temp_dir() function in wp-includes/functions.php is used to determine a writable directory for temporary files. It checks several locations in order: WP_TEMP_DIR constant, sys_get_temp_dir(), upload_tmp_dir PHP setting, WP_CONTENT_DIR, and finally defaults to /tmp/.

Currently, this function lacks dedicated unit test coverage. This patch introduces a new test class Tests_Functions_GetTempDir to verify:

  • The function respects the WP_TEMP_DIR constant when defined.
  • The function returns a path with a trailing slash.
  • The function correctly falls back through the expected order of locations.
  • The returned directory is writable (using wp_is_writable()).

Note: Testing the full fallback logic may require mocking environment settings or constants where possible, or verifying the priority of the returned value.

Change History (2)

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


4 weeks ago
#1

  • Keywords has-patch has-unit-tests added

This PR adds dedicated unit tests for the get_temp_dir() function in wp-includes/functions.php.
The tests ensure that:
•The function returns a path with a trailing slash as expected by its consumers.
•The returned path is an existing, writable directory.
•The WP_TEMP_DIR constant is correctly respected when defined.

To accurately test the constant behaviour without affecting other tests or being affected by the function's internal static cache, @runInSeparateProcess is utilized for the constant-specific test case.

Trac ticket: https://core.trac.wordpress.org/ticket/65651

AI Disclosure:
•AI assistance: Yes
•Tool(s): Junie (JetBrains)
•Model(s): gemini-3-flash-preview
•Used for: Code analysis, test implementation, and workflow management.

#2 @wildworks
4 weeks ago

  • Milestone 7.1Awaiting Review

Since 7.1 Beta 1 has already been released and these functions were not newly introduced with the 7.1 release, I'd like to remove the milestone.

Note: See TracTickets for help on using tickets.