diff --git a/tests/phpunit/tests/functions/getTempDir.php b/tests/phpunit/tests/functions/getTempDir.php new file mode 100644 index 0000000000000..2e660985bcfb2 --- /dev/null +++ b/tests/phpunit/tests/functions/getTempDir.php @@ -0,0 +1,53 @@ +assertStringEndsWith( '/', $temp_dir ); + } + + /** + * Tests that get_temp_dir() returns a writable directory. + * + * @ticket 65651 + */ + public function test_get_temp_dir_is_writable_directory() { + $temp_dir = get_temp_dir(); + $this->assertDirectoryExists( $temp_dir ); + $this->assertTrue( wp_is_writable( $temp_dir ), 'The temporary directory must be writable.' ); + } + + /** + * Tests that get_temp_dir() respects the WP_TEMP_DIR constant. + * + * Since constants cannot be redefined, we use a separate process to test this. + * + * @ticket 65651 + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_get_temp_dir_respects_constant() { + $custom_temp = '/tmp/wp-custom-temp/'; + if ( 'Windows' === PHP_OS_FAMILY ) { + $custom_temp = 'C:\\Windows\\Temp\\wp-custom-temp\\'; + } + + define( 'WP_TEMP_DIR', $custom_temp ); + + $this->assertSame( trailingslashit( $custom_temp ), get_temp_dir() ); + } +}