From 15995a12ccac69e3dee5138ddc01666a67738fc4 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Wed, 21 Oct 2026 23:11:36 +0530 Subject: [PATCH] Tests: Add unit test coverage for wp_is_writable() --- .../phpunit/tests/functions/wpIsWritable.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpIsWritable.php diff --git a/tests/phpunit/tests/functions/wpIsWritable.php b/tests/phpunit/tests/functions/wpIsWritable.php new file mode 100644 index 0000000000000..f2bdb2b013c3d --- /dev/null +++ b/tests/phpunit/tests/functions/wpIsWritable.php @@ -0,0 +1,40 @@ +assertTrue( wp_is_writable( get_temp_dir() ) ); + } + + /** + * @ticket 65819 + */ + public function test_returns_false_for_path_with_missing_parent() { + // Parent directory must not exist so Windows win_is_writable() cannot create the file. + $path = trailingslashit( get_temp_dir() ) . 'wp-is-writable-missing-' . wp_generate_password( 8, false ) . '/file.txt'; + + $this->assertFalse( wp_is_writable( $path ) ); + } + + /** + * @ticket 65819 + */ + public function test_returns_true_for_writable_file() { + $file = wp_tempnam( 'wp-is-writable-' ); + + $this->assertNotFalse( $file ); + $this->assertTrue( wp_is_writable( $file ) ); + + unlink( $file ); + } +}