From 692da0caea0e7be3976bb611c8171c0845289f79 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:40:45 +0000 Subject: [PATCH 01/27] Add `WP_Filesystem_Direct_UnitTestCase`. --- .../filesystem/wpFilesystemDirect/base.php | 198 ++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php new file mode 100644 index 0000000000000..d8c1b2ba8972b --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php @@ -0,0 +1,198 @@ + array( + 'type' => 'd', + 'path' => $test_data_root_dir, + ), + 'test_dir' => array( + 'type' => 'd', + 'path' => $test_data_dir, + ), + 'subdir' => array( + 'type' => 'd', + 'path' => $test_data_dir . 'subdir/', + ), + + // Then files. + 'visible_file' => array( + 'type' => 'f', + 'path' => $test_data_dir . 'a_file_that_exists.txt', + 'contents' => "Contents of a file.\r\nNext line of a file.\r\n", + ), + 'hidden_file' => array( + 'type' => 'f', + 'path' => $test_data_dir . '.a_hidden_file', + 'contents' => "A hidden file.\r\n", + ), + 'subfile' => array( + 'type' => 'f', + 'path' => $test_data_dir . 'subdir/subfile.txt', + 'contents' => "A file in a subdirectory.\r\n", + ), + ); + } + + /** + * Creates any missing test assets before each test. + */ + public function set_up() { + parent::set_up(); + + foreach ( self::$file_structure as $entry ) { + if ( 'd' === $entry['type'] ) { + $this->create_directory_if_needed( $entry['path'] ); + } elseif ( 'f' === $entry['type'] ) { + $this->create_file_if_needed( + $entry['path'], + isset( $entry['contents'] ) ? $entry['contents'] : '' + ); + } + } + } + + /** + * Removes any existing test assets after each test. + */ + public function tear_down() { + foreach ( array_reverse( self::$file_structure ) as $entry ) { + if ( ! file_exists( $entry['path'] ) ) { + continue; + } + + if ( 'f' === $entry['type'] ) { + unlink( $entry['path'] ); + } elseif ( 'd' === $entry['type'] ) { + rmdir( $entry['path'] ); + } + } + + parent::tear_down(); + } + + /** + * Creates a directory if it doesn't already exist. + * + * @throws Exception If the path already exists as a file. + * + * @param string $path The path to the directory. + */ + public function create_directory_if_needed( $path ) { + if ( file_exists( $path ) ) { + if ( is_file( $path ) ) { + throw new Exception( "$path already exists as a file." ); + } + + return; + } + + mkdir( $path ); + } + + /** + * Creates a file if it doesn't already exist. + * + * @throws Exception If the path already exists as a directory. + * + * @param string $path The path to the file. + * @param string $contents Optional. The contents of the file. Default empty string. + */ + public function create_file_if_needed( $path, $contents = '' ) { + if ( file_exists( $path ) ) { + if ( is_dir( $path ) ) { + throw new Exception( "$path already exists as a directory." ); + } + + return; + } + + file_put_contents( $path, $contents ); + } + + /** + * Determines whether the operating system is Windows. + * + * @return bool Whether the operating system is Windows. + */ + public static function is_windows() { + return 'WIN' === substr( PHP_OS, 0, 3 ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_paths_that_exist() { + return array( + 'a file that exists' => array( + 'path' => 'a_file_that_exists.txt', + ), + 'a directory that exists' => array( + 'path' => '', + ), + ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_paths_that_do_not_exist() { + return array( + 'a file that does not exist' => array( + 'path' => 'a_file_that_does_not_exist.txt', + ), + 'a directory that does not exist' => array( + 'path' => 'a_directory_that_does_not_exist', + ), + ); + } + +} From b63661e402f13ad189aedf369db79263ab4fe3a8 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:23 +0000 Subject: [PATCH 02/27] Add tests for `::__construct()`. --- .../wpFilesystemDirect/construct.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php new file mode 100644 index 0000000000000..bddf1da0767a6 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php @@ -0,0 +1,40 @@ +assertSame( + 'direct', + $filesystem->method, + 'The "$method" property is not set to "direct".' + ); + + $this->assertInstanceOf( + 'WP_Error', + $filesystem->errors, + 'The "$errors" property is not set to a WP_Error object.' + ); + } + +} From e9017e2961310ba716f82b46a1dd19ede2fd4b55 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:42:07 +0000 Subject: [PATCH 03/27] Add tests for `::get_contents()`. --- .../wpFilesystemDirect/getContents.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/getContents.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContents.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContents.php new file mode 100644 index 0000000000000..8ba3541ea30d2 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContents.php @@ -0,0 +1,48 @@ +assertSame( + "Contents of a file.\r\nNext line of a file.\r\n", + self::$filesystem->get_contents( $file ) + ); + } + + /** + * Tests that `WP_Filesystem_Direct::get_contents()` + * returns false for a file that does not exist. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_return_false( $path ) { + $this->assertFalse( self::$filesystem->get_contents( self::$file_structure['test_dir']['path'] . $path ) ); + } + +} From d44afd5b6533ee3b037c82aec99e77a2388d1dbd Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:42:02 +0000 Subject: [PATCH 04/27] Add tests for `::get_contents_array()`. --- .../wpFilesystemDirect/getContentsArray.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/getContentsArray.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContentsArray.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContentsArray.php new file mode 100644 index 0000000000000..e75b3f6bb1876 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContentsArray.php @@ -0,0 +1,58 @@ +get_contents_array( $file ); + + $this->assertIsArray( + $contents, + 'The file contents are not an array.' + ); + + $this->assertSameSetsWithIndex( + array( + "Contents of a file.\r\n", + "Next line of a file.\r\n", + ), + $contents, + 'The file contents do not match the expected value.' + ); + } + + /** + * Tests that `WP_Filesystem_Direct::get_contents_array()` + * returns false for a path that does not exist. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_return_false( $path ) { + $this->assertFalse( self::$filesystem->get_contents_array( self::$file_structure['test_dir']['path'] . $path ) ); + } + +} From fe83cf54e362b555159f8134cb189238bc39f303 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:43:05 +0000 Subject: [PATCH 05/27] Add tests for `::put_contents()`. --- .../wpFilesystemDirect/putContents.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/putContents.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/putContents.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/putContents.php new file mode 100644 index 0000000000000..13f12072ff7bd --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/putContents.php @@ -0,0 +1,43 @@ +assertFalse( self::$filesystem->put_contents( self::$file_structure['test_dir']['path'], 'New content.' ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::put_contents()` inserts + * content into the provided file. + * + * @ticket 57774 + */ + public function test_should_insert_contents_into_file() { + $file = self::$file_structure['test_dir']['path'] . 'file-to-create.txt'; + $actual = self::$filesystem->put_contents( $file, 'New content.', 0644 ); + unlink( $file ); + + $this->assertTrue( $actual, 'The contents were not inserted.' ); + } + +} From ec07333e0b9c53fe27911d09ac52256b2a595824 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:29 +0000 Subject: [PATCH 06/27] Add tests for `::cwd()`. --- .../filesystem/wpFilesystemDirect/cwd.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php new file mode 100644 index 0000000000000..15e2382d724bb --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php @@ -0,0 +1,27 @@ +assertSame( wp_normalize_path( dirname( ABSPATH ) ), wp_normalize_path( self::$filesystem->cwd() ) ); + } + +} From 6006b17aaa36cbe0b1aae56df682c0409ba68118 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:40:56 +0000 Subject: [PATCH 07/27] Add tests for `::chdir()`. --- .../filesystem/wpFilesystemDirect/chdir.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php new file mode 100644 index 0000000000000..b40d6d9437189 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php @@ -0,0 +1,96 @@ +cwd(); + $path = wp_normalize_path( realpath( self::$file_structure['test_dir']['path'] ) ) . $path; + $chdir_result = self::$filesystem->chdir( $path ); + $cwd_result = self::$filesystem->cwd(); + + // Reset the current working directory. + self::$filesystem->chdir( $original_cwd ); + + $this->assertFalse( + $chdir_result, + 'Changing working directory succeeded.' + ); + + $this->assertSame( + $original_cwd, + $cwd_result, + 'The current working directory was changed.' + ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_fail_to_change_directory() { + return array( + 'a file that exists' => array( + 'path' => 'a_file_that_exists.txt', + ), + 'a file that does not exist' => array( + 'path' => 'a_file_that_does_not_exist.txt', + ), + 'a directory that does not exist' => array( + 'path' => 'a_directory_that_does_not_exist', + ), + ); + } + + /** + * Tests that `WP_Filesystem_Direct::chdir()` changes to + * an existing directory. + * + * @ticket 57774 + */ + public function test_should_change_directory() { + $original_cwd = self::$filesystem->cwd(); + $path = wp_normalize_path( realpath( self::$file_structure['test_dir']['path'] ) ); + $chdir_result = self::$filesystem->chdir( $path ); + $cwd_result = self::$filesystem->cwd(); + + // Reset the current working directory. + self::$filesystem->chdir( $original_cwd ); + + $this->assertTrue( + $chdir_result, + 'Changing working directory failed.' + ); + + $this->assertSame( + $path, + $cwd_result, + 'The current working directory was incorrect.' + ); + } + +} From dd4284a5ddbf138566910b403a3b876f6234b6bc Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:06 +0000 Subject: [PATCH 08/27] Add tests for `::chgrp()`. --- .../filesystem/wpFilesystemDirect/chgrp.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php new file mode 100644 index 0000000000000..f67ff8c0bd0c4 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php @@ -0,0 +1,33 @@ +assertFalse( self::$filesystem->chgrp( self::$file_structure['test_dir']['path'] . $path, 0 ) ); + } + +} From 98da7673296f066e6b7cad9702c4bbbe6870262f Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:12 +0000 Subject: [PATCH 09/27] Add tests for `::chmod()`. --- .../filesystem/wpFilesystemDirect/chmod.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php new file mode 100644 index 0000000000000..fd09e8108e228 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php @@ -0,0 +1,78 @@ +assertFalse( self::$filesystem->chmod( $path ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::chmod()` should set + * $mode when it is not passed. + * + * This test runs in a separate process so that it can define + * constants without impacting other tests. + * + * This test does not preserve global state to prevent the exception + * "Serialization of 'Closure' is not allowed." when running in a + * separate process. + * + * @ticket 57774 + * + * @dataProvider data_should_set_mode_when_not_passed + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * + * @param string $path The path. + * @param string $type The type of path. "FILE" for file, "DIR" for directory. + */ + public function test_should_handle_set_mode_when_not_passed( $path, $type ) { + define( 'FS_CHMOD_' . $type, ( 'FILE' === $type ? 0644 : 0755 ) ); + + $this->assertTrue( self::$filesystem->chmod( self::$file_structure['test_dir']['path'] . $path, false ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_set_mode_when_not_passed() { + return array( + 'a file' => array( + 'path' => 'a_file_that_exists.txt', + 'type' => 'FILE', + ), + 'a directory' => array( + 'path' => '', + 'type' => 'DIR', + ), + ); + } + +} From 4cf51b463abbd14f6813793e3427820de7be09ea Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:17 +0000 Subject: [PATCH 10/27] Add tests for `::chown()`. --- .../filesystem/wpFilesystemDirect/chown.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php new file mode 100644 index 0000000000000..16ada77afea61 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php @@ -0,0 +1,33 @@ +assertFalse( self::$filesystem->chown( $path, fileowner( __FILE__ ) ) ); + } + +} From aecbc965d33cfd24f911bc50b2e6d2839a91781c Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:54 +0000 Subject: [PATCH 11/27] Add tests for `::getchmod()`. --- .../wpFilesystemDirect/getchmod.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/getchmod.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/getchmod.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getchmod.php new file mode 100644 index 0000000000000..2b0c2ce327afc --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getchmod.php @@ -0,0 +1,48 @@ +getchmod( self::$file_structure['test_dir']['path'] . $path ); + $this->assertNotSame( '', $actual ); + } + + /** + * Tests that `WP_Filesystem_Direct::getchmod()` returns + * the permissions for a path that does not exist. + * + * @dataProvider data_paths_that_do_not_exist + * + * @ticket 57774 + * + * @param string $path The path. + */ + public function test_should_get_chmod_for_a_path_that_does_not_exist( $path ) { + $actual = self::$filesystem->getchmod( self::$file_structure['test_dir']['path'] . $path ); + $this->assertNotSame( '', $actual ); + } +} From e9a89965d50ea3dc838d8e8e3772a56ab3bf4176 Mon Sep 17 00:00:00 2001 From: costdev Date: Mon, 6 Feb 2023 04:28:58 +0000 Subject: [PATCH 12/27] Add tests for `::copy()`. --- .../filesystem/wpFilesystemDirect/copy.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php new file mode 100644 index 0000000000000..e610a3ebd1a1d --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php @@ -0,0 +1,73 @@ +copy( $source, $destination, true ); + + unlink( $destination ); + + $this->assertTrue( $actual ); + } + + /** + * Tests that `WP_Filesystem_Direct::copy()` does not overwrite + * an existing destination when overwriting is disabled. + * + * @ticket 57774 + */ + public function test_should_not_overwrite_an_existing_file_when_overwriting_is_disabled() { + $source = self::$file_structure['test_dir']['path'] . 'a_file_that_exists.txt'; + $destination = self::$file_structure['test_dir']['path'] . 'a_file_that_exists.dest'; + + if ( ! file_exists( $destination ) ) { + touch( $destination ); + } + + $actual = self::$filesystem->copy( $source, $destination ); + + unlink( $destination ); + + $this->assertFalse( $actual ); + } + + /** + * Tests that `WP_Filesystem_Direct::copy()` does not overwrite an existing + * destination when overwriting is enabled and the source and destination + * are the same. + * + * @ticket 57774 + */ + public function test_should_not_overwrite_when_overwriting_is_enabled_and_source_and_destination_are_the_same() { + $source = self::$file_structure['test_dir']['path'] . 'a_file_that_exists.txt'; + $this->assertFalse( self::$filesystem->copy( $source, $source, true ) ); + } + +} From 1d82e7cf8894377131243095a574ac87f2360aeb Mon Sep 17 00:00:00 2001 From: costdev Date: Mon, 6 Feb 2023 08:38:56 +0000 Subject: [PATCH 13/27] Add tests for `::move()`. --- .../filesystem/wpFilesystemDirect/move.php | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php new file mode 100644 index 0000000000000..884d68b26079f --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php @@ -0,0 +1,151 @@ +move( $source, $destination, true ); + + rename( $destination, $source ); + + $this->assertTrue( $actual ); + } + + /** + * Tests that `WP_Filesystem_Direct::move()` does not overwrite + * an existing destination when overwriting is disabled. + * + * @ticket 57774 + */ + public function test_should_not_overwrite_an_existing_file_when_overwriting_is_disabled() { + $source = self::$file_structure['visible_file']['path']; + $destination = self::$file_structure['subfile']['path']; + $actual = self::$filesystem->move( $source, $destination ); + + $this->assertFalse( $actual ); + } + + /** + * Tests that `WP_Filesystem_Direct::move()` moves directories. + * + * @ticket 57774 + */ + public function test_should_move_directories() { + $source = self::$file_structure['test_dir']['path']; + $destination = untrailingslashit( self::$file_structure['test_dir']['path'] ) . '-dest'; + $actual = self::$filesystem->move( $source, $destination, true ); + + $source_exists = is_dir( $source ); + $destination_exists = is_dir( $destination ); + + if ( $actual ) { + $restored = rename( $destination, $source ); + } + + $this->assertTrue( $actual, 'The directory was not moved.' ); + $this->assertFalse( $source_exists, 'The source still exists.' ); + $this->assertTrue( $destination_exists, 'The destination does not exist.' ); + $this->assertTrue( $restored, 'The test assets were not cleaned up after the test.' ); + } + + /** + * Tests that `WP_Filesystem_Direct::move()` returns false for an + * invalid destination. + * + * @ticket 57774 + */ + public function test_should_return_false_for_invalid_destination() { + $source = self::$file_structure['test_dir']['path']; + $destination = 'http://example.org'; + + $this->assertFalse( self::$filesystem->move( $source, $destination, true ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::move()` returns false for an + * invalid destination. + * + * @ticket 57774 + */ + public function test_should_return_false_when_overwriting_is_enabled_the_destination_exists_but_cannot_be_deleted() { + global $wp_filesystem; + $wpfilesystem_backup = $wp_filesystem; + + // Force failure conditions. + $filesystem_mock = $this->getMockBuilder( 'WP_Filesystem_Direct' ) + // Note: setMethods() is deprecated in PHPUnit 9, but still supported. + ->setMethods( array( 'exists', 'delete' ) ) + ->setConstructorArgs( array( null ) ) + ->getMock(); + + $filesystem_mock->expects( $this->once() )->method( 'exists' )->willReturn( true ); + $filesystem_mock->expects( $this->once() )->method( 'delete' )->willReturn( false ); + $wp_filesystem = $filesystem_mock; + + $actual = $wp_filesystem->move( + self::$file_structure['test_dir']['path'], + self::$file_structure['subdir']['path'], + true + ); + + // Restore the filesystem. + $wp_filesystem = $wpfilesystem_backup; + + $this->assertFalse( $actual ); + } + + /** + * Tests that `WP_Filesystem_Direct::move()` falls back to a single + * file copy when the source and destination do not exist. + * + * @ticket 57774 + */ + public function test_should_fall_back_to_single_file_copy_when_source_and_destination_do_not_exist() { + global $wp_filesystem; + + $source = self::$file_structure['test_dir']['path'] . 'a_file_that_does_not_exist.txt'; + $destination = self::$file_structure['test_dir']['path'] . 'another_file_that_does_not_exist.txt'; + + // Set up mock filesystem. + $filesystem_mock = $this->getMockBuilder( 'WP_Filesystem_Direct' ) + ->setConstructorArgs( array( null ) ) + // Note: setMethods() is deprecated in PHPUnit 9, but still supported. + ->setMethods( array( 'exists', 'delete', 'is_file', 'copy' ) ) + ->getMock(); + + $filesystem_mock->expects( $this->exactly( 2 ) )->method( 'exists' )->willReturn( array( true, true ) ); + $filesystem_mock->expects( $this->exactly( 2 ) )->method( 'delete' )->willReturn( array( true, false ) ); + $filesystem_mock->expects( $this->once() )->method( 'is_file' )->willReturn( true ); + $filesystem_mock->expects( $this->once() )->method( 'copy' )->willReturn( true ); + + $wp_filesystem_backup = $wp_filesystem; + $wp_filesystem = $filesystem_mock; + + $actual = $filesystem_mock->move( $source, $destination, true ); + $wp_filesystem = $wp_filesystem_backup; + + $this->assertTrue( $actual ); + } + +} From 59c8b1937593227d9c25dcda2e5725490283def8 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:35 +0000 Subject: [PATCH 14/27] Add tests for `::delete()`. --- .../filesystem/wpFilesystemDirect/delete.php | 205 ++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php new file mode 100644 index 0000000000000..3e2a61f3154cd --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php @@ -0,0 +1,205 @@ +assertFalse( self::$filesystem->delete( '' ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::delete()` deletes an empty directory. + * + * @ticket 57774 + */ + public function test_should_delete_an_empty_directory() { + $dir = self::$file_structure['test_dir']['path'] . 'directory-to-delete'; + + $this->assertTrue( + mkdir( $dir ), + 'The directory was not created.' + ); + + $this->assertTrue( + self::$filesystem->delete( $dir ), + 'The directory was not deleted.' + ); + } + + /** + * Tests that `WP_Filesystem_Direct::delete()` deletes a directory with contents. + * + * @ticket 57774 + */ + public function test_should_delete_a_directory_with_contents() { + $this->assertTrue( + self::$filesystem->delete( self::$file_structure['test_dir']['path'], true ), + 'Directory deletion failed.' + ); + + $this->assertDirectoryDoesNotExist( + self::$file_structure['test_dir']['path'], + 'The directory was not deleted.' + ); + } + + /** + * Tests that `WP_Filesystem_Direct::delete()` deletes a file. + * + * @ticket 57774 + * + * @dataProvider data_should_delete_a_file + * + * @param string $key The key for the file in `self::$filesystem_structure`. + */ + public function test_should_delete_a_file( $file ) { + $file = self::$file_structure[ $file ]['path'] . $file; + + $this->assertTrue( self::$filesystem->delete( $file ), 'File deletion failed.' ); + $this->assertFileDoesNotExist( $file, 'The file was not deleted.' ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_delete_a_file() { + return array( + 'A visible file' => array( + 'key' => 'visible_file', + ), + 'A hidden file' => array( + 'key' => 'hidden_file', + ), + ); + } + + /** + * Tests that `WP_Filesystem_Direct::delete()` + * returns true when deleting a path that does not exist. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_return_true_when_deleting_path_that_does_not_exist( $path ) { + $path = self::$file_structure['test_dir']['path'] . $path; + + /* + * Verify that the path doesn't exist before testing. + * + * assertFileDoesNotExist() uses file_exists(), which returns the same result for both + * files and directories. + * assertDirectoryDoesNotExist() uses is_dir(), which tests strictly for a directory. + * + * For more useful debugging in the event of a failure, test for a directory first. + */ + $this->assertDirectoryDoesNotExist( $path, "$path already existed as a directory before testing." ); + $this->assertFileDoesNotExist( $path, "$path already existed as a file before testing." ); + + $this->assertTrue( self::$filesystem->delete( $path ), 'Attempting to delete a non-existent path should return true.' ); + } + + /** + * Tests that `WP_Filesystem_Direct::delete()` + * returns false when a directory's contents cannot be deleted. + * + * @ticket 57774 + */ + public function test_should_return_false_when_contents_cannot_be_deleted() { + global $wp_filesystem; + + $wp_filesystem = new WP_Filesystem_Direct( array() ); + + $path = self::$file_structure['test_dir']['path'] . 'dir-to-delete/'; + + if ( ! is_dir( $path ) ) { + mkdir( $path ); + } + + // Set up mock filesystem. + $filesystem_mock = $this->getMockBuilder( 'WP_Filesystem_Direct' ) + ->setConstructorArgs( array( null ) ) + // Note: setMethods() is deprecated in PHPUnit 9, but still supported. + ->setMethods( array( 'dirlist' ) ) + ->getMock(); + + $filesystem_mock->expects( $this->once() ) + ->method( 'dirlist' ) + ->willReturn( + array( 'a_file_that_does_not_exist.txt' => array( 'type' => 'f' ) ) + ); + + $wp_filesystem_backup = $wp_filesystem; + $wp_filesystem = $filesystem_mock; + + $actual = $filesystem_mock->delete( $path, true ); + + if ( $actual ) { + rmdir( $path ); + } + + $wp_filesystem = $wp_filesystem_backup; + + $this->assertFalse( $actual ); + } + + /** + * Tests that `WP_Filesystem_Direct::delete()` + * returns false when the path is not a file or directory, but exists. + * + * @ticket 57774 + */ + public function test_should_return_false_when_path_exists_but_is_not_a_file_or_directory() { + global $wp_filesystem; + + $wp_filesystem = new WP_Filesystem_Direct( array() ); + + // Set up mock filesystem. + $filesystem_mock = $this->getMockBuilder( 'WP_Filesystem_Direct' ) + ->setConstructorArgs( array( null ) ) + // Note: setMethods() is deprecated in PHPUnit 9, but still supported. + ->setMethods( array( 'is_file', 'dirlist' ) ) + ->getMock(); + + $filesystem_mock->expects( $this->once() ) + ->method( 'is_file' ) + ->willReturn( false ); + + $filesystem_mock->expects( $this->once() ) + ->method( 'dirlist' ) + ->willReturn( false ); + + $wp_filesystem_backup = $wp_filesystem; + $wp_filesystem = $filesystem_mock; + + $actual = $filesystem_mock->delete( self::$file_structure['subdir']['path'], true ); + + $wp_filesystem = $wp_filesystem_backup; + + $this->assertFalse( $actual ); + } + +} From 7c083c551db66daa52e8035757e47b4ebabe5d1a Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:47 +0000 Subject: [PATCH 15/27] Add tests for `::exists()`. --- .../filesystem/wpFilesystemDirect/exists.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php new file mode 100644 index 0000000000000..731ef05453ff0 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php @@ -0,0 +1,45 @@ +assertTrue( self::$filesystem->exists( self::$file_structure['test_dir']['path'] . $path ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::exists()` determines that + * a path does not exist. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path to check. + */ + public function test_should_determine_that_a_path_does_not_exist( $path ) { + $this->assertFalse( self::$filesystem->exists( self::$file_structure['test_dir']['path'] . $path ) ); + } + +} From 9991f8bfeab54f8090f7ed4bfd3d667c414d3d73 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:42:33 +0000 Subject: [PATCH 16/27] Add tests for `::is_file()`. --- .../filesystem/wpFilesystemDirect/isFile.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php new file mode 100644 index 0000000000000..8aa43e937f1c7 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php @@ -0,0 +1,62 @@ +assertTrue( self::$filesystem->is_file( self::$file_structure['test_dir']['path'] . 'a_file_that_exists.txt' ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::is_file()` determies that + * a path is not a file. + * + * @ticket 57774 + * + * @dataProvider data_should_determine_if_a_path_is_not_a_file + * + * @param string $path The path to check. + */ + public function test_should_determine_that_a_path_is_not_a_file( $path ) { + $this->assertFalse( self::$filesystem->is_file( self::$file_structure['test_dir']['path'] . $path ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_determine_if_a_path_is_not_a_file() { + return array( + 'a file that does not exist' => array( + 'path' => 'a_file_that_does_not_exist.txt', + ), + 'a directory that exists' => array( + 'path' => '', + ), + 'a directory that does not exist' => array( + 'path' => 'a_directory_that_does_not_exist', + ), + ); + } + +} From 6aad2db9f86a065799adb082f3e8c53f70151708 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:42:28 +0000 Subject: [PATCH 17/27] Add tests for `::is_dir()`. --- .../filesystem/wpFilesystemDirect/isDir.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/isDir.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isDir.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isDir.php new file mode 100644 index 0000000000000..1a367851f6a78 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isDir.php @@ -0,0 +1,63 @@ +assertTrue( self::$filesystem->is_dir( self::$file_structure['test_dir']['path'] ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::is_directory()` determines that + * a path is not a directory. + * + * @ticket 57774 + * + * @dataProvider data_should_determine_that_a_path_is_not_a_directory + * + * @param string $path The path to check. + * @param string $type The type of resource. Accepts 'f' or 'd'. + * Used to invert $expected due to data provider setup. + */ + public function test_should_determine_that_a_path_is_not_a_directory( $path ) { + $this->assertFalse( self::$filesystem->is_dir( self::$file_structure['test_dir']['path'] . $path ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_determine_that_a_path_is_not_a_directory() { + return array( + 'a file that exists' => array( + 'path' => 'a_file_that_exists.txt', + ), + 'a file that does not exist' => array( + 'path' => 'a_file_that_does_not_exist.txt', + ), + 'a directory that does not exist' => array( + 'path' => 'a_directory_that_does_not_exist', + ), + ); + } +} From 2cfd4159e777516834281423907cc75122717951 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:42:38 +0000 Subject: [PATCH 18/27] Add tests for `::is_readable()`. --- .../wpFilesystemDirect/isReadable.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php new file mode 100644 index 0000000000000..92a27ae213c95 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php @@ -0,0 +1,47 @@ +assertTrue( self::$filesystem->is_readable( self::$file_structure['test_dir']['path'] . $path ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::is_readable()` determines that + * a path is not readable. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_determine_that_a_path_is_not_readable( $path ) { + $this->assertFalse( self::$filesystem->is_readable( self::$file_structure['test_dir']['path'] . $path ) ); + } + +} From 8af87a4e5c669679d7d5b9c5ff45b134b60fd57b Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:42:46 +0000 Subject: [PATCH 19/27] Add tests for `::is_writable()`. --- .../wpFilesystemDirect/isWritable.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php new file mode 100644 index 0000000000000..34ab6438a51f9 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php @@ -0,0 +1,47 @@ +assertTrue( self::$filesystem->is_writable( self::$file_structure['test_dir']['path'] . $path ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::is_writable()` determines that + * a path is not writable. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_determine_that_a_path_is_not_writable( $path ) { + $this->assertFalse( self::$filesystem->is_writable( self::$file_structure['test_dir']['path'] . $path ) ); + } + +} From bb4ffc5c0e35d4379ed05a9a1816a97c6af1e2e2 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:40:20 +0000 Subject: [PATCH 20/27] Add tests for `::atime()`. --- .../filesystem/wpFilesystemDirect/atime.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php new file mode 100644 index 0000000000000..d45f16ef17a45 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php @@ -0,0 +1,51 @@ +assertIsInt( self::$filesystem->atime( $path ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::atime()` + * returns false for a path that does not exist. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_return_false_for_a_path_that_does_not_exist( $path ) { + $path = self::$file_structure['test_dir']['path'] . $path; + + $this->assertFalse( self::$filesystem->atime( $path ) ); + } + +} From 0676fc08acd4709b0e86ea2e6075c3ce3db37197 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:42:59 +0000 Subject: [PATCH 21/27] Add tests for `::mtime()`. --- .../filesystem/wpFilesystemDirect/mtime.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php new file mode 100644 index 0000000000000..5e458a3b7c1bc --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php @@ -0,0 +1,69 @@ +mtime( self::$file_structure['test_dir']['path'] . $path ); + $has_mtime = false !== $result; + + $this->assertTrue( + $has_mtime, + 'The mtime was not determined.' + ); + + $this->assertIsInt( + $result, + 'The mtime is not an integer.' + ); + } + + /** + * Tests that `WP_Filesystem_Direct::mtime()` does not determine + * the mtime of a path. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_not_determine_file_modified_time( $path ) { + $result = self::$filesystem->mtime( self::$file_structure['test_dir']['path'] . $path ); + $has_mtime = false !== $result; + + $this->assertFalse( + $has_mtime, + 'An mtime was determined.' + ); + + $this->assertIsNotInt( + $result, + 'The mtime is an integer.' + ); + } + +} From 20ba6e47e40d698c9cb9d61e72985932f1f1a3ed Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:43:19 +0000 Subject: [PATCH 22/27] Add tests for `::size()`. --- .../filesystem/wpFilesystemDirect/size.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php new file mode 100644 index 0000000000000..39f68e55c8166 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php @@ -0,0 +1,64 @@ +size( self::$file_structure['test_dir']['path'] . $path ); + $has_filesize = false !== $result; + + $this->assertTrue( + $has_filesize, + 'The file size was not determined.' + ); + + $this->assertIsInt( + $result, + 'The file size is not an integer.' + ); + } + + /** + * Tests that `WP_Filesystem_Direct::size()` does not determine + * the filesize of a path that does not exist. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_not_determine_file_size( $path ) { + $result = self::$filesystem->size( self::$file_structure['test_dir']['path'] . $path ); + $has_filesize = false !== $result; + + $this->assertFalse( + $has_filesize, + 'A file size was determined.' + ); + } + +} From bdb8c546c8d0d91de7187c4ff7510b9d82c19951 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:43:24 +0000 Subject: [PATCH 23/27] Add tests for `::touch()`. --- .../filesystem/wpFilesystemDirect/touch.php | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php new file mode 100644 index 0000000000000..c0eddad6a815a --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php @@ -0,0 +1,94 @@ +touch( $file, $mtime, $atime ); + + $actual_atime = fileatime( $file ); + $actual_exists = file_exists( $file ); + $actual_mtime = filemtime( $file ); + + if ( $actual_exists ) { + unlink( $file ); + } + + $this->assertTrue( $result, 'WP_Filesystem_Direct::touch() did not return true.' ); + $this->assertTrue( $actual_exists, 'The file does not exist.' ); + $this->assertSame( $actual_atime, $expected_atime, 'The file does not have the expected atime.' ); + $this->assertSame( $actual_mtime, $expected_mtime, 'The file does not have the expected mtime.' ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_create_file() { + return array( + 'default mtime or atime' => array( + 'file' => 'TEST_DATA/file-to-create.txt', + 'mtime' => 0, + 'atime' => 0, + ), + 'set mtime and default atime' => array( + 'file' => 'TEST_DATA/file-to-create.txt', + 'mtime' => 'time plus one minute', + 'atime' => 'time', + ), + 'default mtime and set atime' => array( + 'file' => 'TEST_DATA/file-to-create.txt', + 'mtime' => 'time', + 'atime' => 'time plus one minute', + ), + ); + } + +} From 5a970837f0caa8601a2d4dd24c07ecdd3f04cea7 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:42:53 +0000 Subject: [PATCH 24/27] Add tests for `::mkdir()`. --- .../filesystem/wpFilesystemDirect/mkdir.php | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php new file mode 100644 index 0000000000000..3ef7c52a80c87 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php @@ -0,0 +1,212 @@ +mkdir( $path ); + + if ( $path !== self::$file_structure['test_dir']['path'] && is_dir( $path ) ) { + rmdir( $path ); + } + + $this->assertTrue( $actual ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_create_directory() { + return array( + 'no trailing slash' => array( + 'path' => 'TEST_DIR/directory-to-create', + ), + 'a trailing slash' => array( + 'path' => 'TEST_DIR/directory-to-create/', + ), + ); + } + + /** + * Tests that `WP_Filesystem_Direct::mkdir()` does not create a directory. + * + * This test runs in a separate process so that it can define + * constants without impacting other tests. + * + * This test does not preserve global state to prevent the exception + * "Serialization of 'Closure' is not allowed." when running in a + * separate process. + * + * @ticket 57774 + * + * @dataProvider data_should_not_create_directory + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * + * @param mixed $path The path to create. + */ + public function test_should_not_create_directory( $path ) { + define( 'FS_CHMOD_DIR', 0755 ); + + $path = str_replace( 'TEST_DIR', self::$file_structure['test_dir']['path'], $path ); + $actual = self::$filesystem->mkdir( $path ); + + if ( $path !== self::$file_structure['test_dir']['path'] && is_dir( $path ) ) { + rmdir( $path ); + } + + $this->assertFalse( $actual ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_not_create_directory() { + return array( + 'empty path' => array( + 'path' => '', + ), + 'a path that exists' => array( + 'path' => 'TEST_DIR', + ), + ); + } + + /** + * Tests that `WP_Filesystem_Direct::mkdir()` sets chmod. + * + * @ticket 57774 + */ + public function test_should_set_chmod() { + $path = self::$file_structure['test_dir']['path'] . 'directory-to-create'; + + $created = self::$filesystem->mkdir( $path, 0644 ); + $chmod = substr( sprintf( '%o', fileperms( $path ) ), -4 ); + + if ( $path !== self::$file_structure['test_dir']['path'] && is_dir( $path ) ) { + rmdir( $path ); + } + + $expected_permissions = $this->is_windows() ? '0777' : '0644'; + + $this->assertTrue( $created, 'The directory was not created.' ); + $this->assertSame( $expected_permissions, $chmod, 'The permissions are incorrect.' ); + } + + /** + * Tests that `WP_Filesystem_Direct::mkdir()` sets the owner. + * + * This test runs in a separate process so that it can define + * constants without impacting other tests. + * + * This test does not preserve global state to prevent the exception + * "Serialization of 'Closure' is not allowed." when running in a + * separate process. + * + * @ticket 57774 + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_should_set_owner() { + define( 'FS_CHMOD_DIR', 0755 ); + + $path = self::$file_structure['test_dir']['path'] . 'directory-to-create'; + + // Get the default owner. + self::$filesystem->mkdir( $path ); + $original_owner = fileowner( $path ); + + rmdir( $path ); + + $expected_group = $this->is_windows() ? $original_owner : $original_owner + 1; + $created = self::$filesystem->mkdir( $path, 0755, $expected_group ); + $owner = fileowner( $path ); + + if ( $path !== self::$file_structure['test_dir']['path'] && is_dir( $path ) ) { + rmdir( $path ); + } + + $this->assertTrue( $created, 'The directory was not created.' ); + $this->assertSame( $expected_group, $owner, 'The owner is incorrect.' ); + } + + /** + * Tests that `WP_Filesystem_Direct::mkdir()` sets the group. + * + * This test runs in a separate process so that it can define + * constants without impacting other tests. + * + * This test does not preserve global state to prevent the exception + * "Serialization of 'Closure' is not allowed." when running in a + * separate process. + * + * @ticket 57774 + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_should_set_group() { + define( 'FS_CHMOD_DIR', 0755 ); + + $path = self::$file_structure['test_dir']['path'] . 'directory-to-create'; + + // Get the default group. + self::$filesystem->mkdir( $path ); + $original_group = filegroup( $path ); + + rmdir( $path ); + + $expected_group = $this->is_windows() ? $original_group : $original_group + 1; + $created = self::$filesystem->mkdir( $path, 0755, false, $expected_group ); + $group = filegroup( $path ); + + if ( $path !== self::$file_structure['test_dir']['path'] && is_dir( $path ) ) { + rmdir( $path ); + } + + $this->assertTrue( $created, 'The directory was not created.' ); + $this->assertSame( $expected_group, $group, 'The group is incorrect.' ); + } + +} From 9ec8923f46cf3462a708160fcfe1997aa65052a8 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:43:11 +0000 Subject: [PATCH 25/27] Add tests for `::rmdir()`. --- .../filesystem/wpFilesystemDirect/rmdir.php | 201 ++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php new file mode 100644 index 0000000000000..3de09fe5cc9c9 --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php @@ -0,0 +1,201 @@ +assertFalse( self::$filesystem->rmdir( '' ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::rmdir()` deletes an empty directory. + * + * @ticket 57774 + */ + public function test_should_delete_an_empty_directory() { + $dir = self::$file_structure['test_dir']['path'] . 'directory-to-delete/'; + + if ( ! is_dir( $dir ) ) { + mkdir( $dir ); + } + + $actual = self::$filesystem->rmdir( $dir ); + + if ( ! $actual ) { + rmdir( $dir ); + } + + $this->assertTrue( $actual, 'The directory was not deleted.' ); + } + + /** + * Tests that `WP_Filesystem_Direct::rmdir()` recursively deletes + * a directory with contents. + * + * @ticket 57774 + */ + public function test_should_recursively_delete_a_directory() { + $dir = self::$file_structure['test_dir']['path'] . 'directory-to-delete/'; + $file = $dir . 'file-to-delete.txt'; + $subdir = $dir . 'subdirectory-to-delete/'; + $subfile = $subdir . 'subfile-to-delete.txt'; + + mkdir( $dir, 0755 ); + mkdir( $subdir, 0755 ); + touch( $file, 0644 ); + touch( $subfile, 0644 ); + + $actual = self::$filesystem->rmdir( self::$file_structure['test_dir']['path'], true ); + + if ( ! $actual ) { + unlink( $file ); + unlink( $subfile ); + rmdir( $subdir ); + rmdir( $dir ); + } + + $this->assertTrue( $actual, 'The directory was deleted.' ); + } + + /** + * Tests that `WP_Filesystem_Direct::rmdir()` deletes a file. + * + * @ticket 57774 + */ + public function test_should_delete_a_file() { + $file = self::$file_structure['test_dir']['path'] . 'file-to-delete.txt'; + + touch( $file ); + + $actual = self::$filesystem->rmdir( $file ); + + if ( ! $actual ) { + unlink( $file ); + } + + $this->assertTrue( $actual, 'The directory was not deleted.' ); + } + + /** + * Tests that `WP_Filesystem_Direct::rmdir()` + * returns true when deleting a path that does not exist. + * + * @ticket 57774 + * + * @dataProvider data_paths_that_do_not_exist + * + * @param string $path The path. + */ + public function test_should_return_true_when_deleting_path_that_does_not_exist( $path ) { + if ( + '' === $path + || str_starts_with( $path, '.' ) + || str_starts_with( $path, '/' ) + ) { + $this->markTestSkipped( 'Dangerous delete path.' ); + } + + $this->assertTrue( self::$filesystem->rmdir( self::$file_structure['test_dir']['path'] . $path ) ); + } + + /** + * Tests that `WP_Filesystem_Direct::rmdir()` + * returns false when a directory's contents cannot be deleted. + * + * @ticket 57774 + */ + public function test_should_return_false_when_contents_cannot_be_deleted() { + + global $wp_filesystem; + + $wp_filesystem = new WP_Filesystem_Direct( array() ); + + $path = self::$file_structure['test_dir']['path'] . 'dir-to-delete/'; + + if ( ! is_dir( $path ) ) { + mkdir( $path ); + } + + // Set up mock filesystem. + $filesystem_mock = $this->getMockBuilder( 'WP_Filesystem_Direct' ) + ->setConstructorArgs( array( null ) ) + // Note: setMethods() is deprecated in PHPUnit 9, but still supported. + ->setMethods( array( 'dirlist' ) ) + ->getMock(); + + $filesystem_mock->expects( $this->once() ) + ->method( 'dirlist' ) + ->willReturn( + array( 'a_file_that_does_not_exist.txt' => array( 'type' => 'f' ) ) + ); + + $wp_filesystem_backup = $wp_filesystem; + $wp_filesystem = $filesystem_mock; + + $actual = $filesystem_mock->rmdir( $path, true ); + + if ( $actual ) { + rmdir( $path ); + } + + $wp_filesystem = $wp_filesystem_backup; + + $this->assertFalse( $actual ); + } + + /** + * Tests that `WP_Filesystem_Direct::rmdir()` + * returns false when the path is not a file or directory, but exists. + * + * @ticket 57774 + */ + public function test_should_return_false_when_path_exists_but_is_not_a_file_or_directory() { + global $wp_filesystem; + + $wp_filesystem = new WP_Filesystem_Direct( array() ); + + // Set up mock filesystem. + $filesystem_mock = $this->getMockBuilder( 'WP_Filesystem_Direct' ) + ->setConstructorArgs( array( null ) ) + // Note: setMethods() is deprecated in PHPUnit 9, but still supported. + ->setMethods( array( 'is_file', 'dirlist' ) ) + ->getMock(); + + $filesystem_mock->expects( $this->once() ) + ->method( 'is_file' ) + ->willReturn( false ); + + $filesystem_mock->expects( $this->once() ) + ->method( 'dirlist' ) + ->willReturn( false ); + + $wp_filesystem_backup = $wp_filesystem; + $wp_filesystem = $filesystem_mock; + + $actual = $filesystem_mock->rmdir( self::$file_structure['subdir']['path'], true ); + + $wp_filesystem = $wp_filesystem_backup; + + $this->assertFalse( $actual ); + } + +} From 29a9c6519cc1988cf613d89fc2bf800ddc95b83f Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 5 Feb 2023 03:41:41 +0000 Subject: [PATCH 26/27] Add tests for `::dirlist()`. --- .../filesystem/wpFilesystemDirect/dirlist.php | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php new file mode 100644 index 0000000000000..9168bc64efaab --- /dev/null +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php @@ -0,0 +1,131 @@ +dirlist( self::$file_structure['test_dir']['path'] . $path, $include_hidden, $recursive ); + + if ( is_array( $expected ) ) { + $this->assertSameSets( + $expected, + array_keys( $actual ), + 'The array keys do not match.' + ); + } else { + $this->assertFalse( + $actual, + '`WP_Filesystem_Direct::dirlist()` did not return false.' + ); + } + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_get_dirlist() { + return array( + 'a directory that exists excluding hidden files' => array( + 'path' => '', + 'include_hidden' => false, + 'recursive' => false, + 'expected' => array( + 'a_file_that_exists.txt', + 'subdir', + ), + ), + 'a directory that exists including hidden files' => array( + 'path' => '', + 'include_hidden' => true, + 'recursive' => false, + 'expected' => array( + 'a_file_that_exists.txt', + '.a_hidden_file', + 'subdir', + ), + ), + 'a directory that does not exist' => array( + 'path' => 'a_directory_that_does_not_exist/', + 'include_hidden' => true, + 'recursive' => false, + 'expected' => false, + ), + 'a file that exists' => array( + 'path' => 'a_file_that_exists.txt', + 'include_hidden' => true, + 'recursive' => false, + 'expected' => array( + 'a_file_that_exists.txt', + ), + ), + 'a file that does not exist' => array( + 'path' => 'a_file_that_does_not_exist.txt', + 'include_hidden' => true, + 'recursive' => false, + 'expected' => false, + ), + ); + } + + /** + * Tests that `WP_Filesystem_Direct::dirlist()` recurses + * into a subdirectory. + * + * @ticket 57774 + */ + public function test_should_recurse_into_subdirectory() { + $actual = self::$filesystem->dirlist( self::$file_structure['test_dir']['path'], true, true ); + + $this->assertIsArray( $actual, 'Did not return an array.' ); + $this->assertArrayHasKey( 'subdir', $actual, 'The subdirectory was not detected.' ); + $this->assertArrayHasKey( 'files', $actual['subdir'], 'The subdirectory does not have a "files" key.' ); + $this->assertNotEmpty( $actual['subdir']['files'], "The subdirectory's contents were not retrieved." ); + $this->assertArrayHasKey( 'subfile.txt', $actual['subdir']['files'], 'The subfile was not detected.' ); + } + + /** + * Tests that `WP_Filesystem_Direct::dirlist()` should not recurse + * into a subdirectory. + * + * @ticket 57774 + */ + public function test_should_not_recurse_into_subdirectory() { + + $actual = self::$filesystem->dirlist( self::$file_structure['test_dir']['path'], true, false ); + + $this->assertIsArray( $actual, 'Did not return an array.' ); + $this->assertArrayHasKey( 'subdir', $actual, 'The subdirectory was not detected.' ); + $this->assertArrayHasKey( 'files', $actual['subdir'], 'The "files" key was not set.' ); + $this->assertIsArray( $actual['subdir']['files'], 'The "files" key was not set to an array.' ); + $this->assertEmpty( $actual['subdir']['files'], 'The "files" array was not empty.' ); + } + +} From e7a90a5ebd188aecb124790c87b0352fcb9982eb Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sat, 2 Mar 2024 14:46:48 +0100 Subject: [PATCH 27/27] Remove empty lines to please PHPCS --- tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php | 1 - .../phpunit/tests/filesystem/wpFilesystemDirect/getContents.php | 1 - .../tests/filesystem/wpFilesystemDirect/getContentsArray.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php | 1 - .../phpunit/tests/filesystem/wpFilesystemDirect/putContents.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php | 1 - tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php | 1 - 24 files changed, 24 deletions(-) diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php index d45f16ef17a45..c6f57780c01c5 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/atime.php @@ -47,5 +47,4 @@ public function test_should_return_false_for_a_path_that_does_not_exist( $path ) $this->assertFalse( self::$filesystem->atime( $path ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php index d8c1b2ba8972b..dc1252bd3a29c 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php @@ -194,5 +194,4 @@ public function data_paths_that_do_not_exist() { ), ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php index b40d6d9437189..cdea47928b2f2 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chdir.php @@ -92,5 +92,4 @@ public function test_should_change_directory() { 'The current working directory was incorrect.' ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php index f67ff8c0bd0c4..a56e5c5ac2b41 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chgrp.php @@ -29,5 +29,4 @@ class Tests_Filesystem_WpFilesystemDirect_Chgrp extends WP_Filesystem_Direct_Uni public function test_should_fail_to_change_file_group( $path ) { $this->assertFalse( self::$filesystem->chgrp( self::$file_structure['test_dir']['path'] . $path, 0 ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php index fd09e8108e228..4deb47c4f09fb 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php @@ -74,5 +74,4 @@ public function data_should_set_mode_when_not_passed() { ), ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php index 16ada77afea61..040693b03c54c 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/chown.php @@ -29,5 +29,4 @@ class Tests_Filesystem_WpFilesystemDirect_Chown extends WP_Filesystem_Direct_Uni public function test_should_return_false( $path ) { $this->assertFalse( self::$filesystem->chown( $path, fileowner( __FILE__ ) ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php index bddf1da0767a6..e8c475a9ee044 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/construct.php @@ -36,5 +36,4 @@ public function test_should_set_method_and_errors() { 'The "$errors" property is not set to a WP_Error object.' ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php index e610a3ebd1a1d..d0355c20e5662 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/copy.php @@ -69,5 +69,4 @@ public function test_should_not_overwrite_when_overwriting_is_enabled_and_source $source = self::$file_structure['test_dir']['path'] . 'a_file_that_exists.txt'; $this->assertFalse( self::$filesystem->copy( $source, $source, true ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php index 15e2382d724bb..c4ce9617314cb 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/cwd.php @@ -23,5 +23,4 @@ class Tests_Filesystem_WpFilesystemDirect_Cwd extends WP_Filesystem_Direct_UnitT public function test_should_get_current_working_directory() { $this->assertSame( wp_normalize_path( dirname( ABSPATH ) ), wp_normalize_path( self::$filesystem->cwd() ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php index 3e2a61f3154cd..4afe54890a5f3 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/delete.php @@ -201,5 +201,4 @@ public function test_should_return_false_when_path_exists_but_is_not_a_file_or_d $this->assertFalse( $actual ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php index 9168bc64efaab..04dab2a48a612 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/dirlist.php @@ -127,5 +127,4 @@ public function test_should_not_recurse_into_subdirectory() { $this->assertIsArray( $actual['subdir']['files'], 'The "files" key was not set to an array.' ); $this->assertEmpty( $actual['subdir']['files'], 'The "files" array was not empty.' ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php index 731ef05453ff0..11eb32621da6a 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/exists.php @@ -41,5 +41,4 @@ public function test_should_determine_that_a_path_exists( $path ) { public function test_should_determine_that_a_path_does_not_exist( $path ) { $this->assertFalse( self::$filesystem->exists( self::$file_structure['test_dir']['path'] . $path ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContents.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContents.php index 8ba3541ea30d2..fed713239a48e 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContents.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContents.php @@ -44,5 +44,4 @@ public function test_should_get_the_contents_of_a_file() { public function test_should_return_false( $path ) { $this->assertFalse( self::$filesystem->get_contents( self::$file_structure['test_dir']['path'] . $path ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContentsArray.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContentsArray.php index e75b3f6bb1876..0e09822c07328 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContentsArray.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/getContentsArray.php @@ -54,5 +54,4 @@ public function test_should_get_the_contents_of_a_file_as_an_array() { public function test_should_return_false( $path ) { $this->assertFalse( self::$filesystem->get_contents_array( self::$file_structure['test_dir']['path'] . $path ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php index 8aa43e937f1c7..e0471f309b62f 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isFile.php @@ -58,5 +58,4 @@ public function data_should_determine_if_a_path_is_not_a_file() { ), ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php index 92a27ae213c95..9ccde92c709ac 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isReadable.php @@ -43,5 +43,4 @@ public function test_should_determine_that_a_path_is_readable( $path ) { public function test_should_determine_that_a_path_is_not_readable( $path ) { $this->assertFalse( self::$filesystem->is_readable( self::$file_structure['test_dir']['path'] . $path ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php index 34ab6438a51f9..f3a1e0ea757de 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/isWritable.php @@ -43,5 +43,4 @@ public function test_should_determine_that_a_path_is_writable( $path ) { public function test_should_determine_that_a_path_is_not_writable( $path ) { $this->assertFalse( self::$filesystem->is_writable( self::$file_structure['test_dir']['path'] . $path ) ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php index 3ef7c52a80c87..53fc1575f32c7 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/mkdir.php @@ -208,5 +208,4 @@ public function test_should_set_group() { $this->assertTrue( $created, 'The directory was not created.' ); $this->assertSame( $expected_group, $group, 'The group is incorrect.' ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php index 884d68b26079f..a6822a90f418b 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/move.php @@ -147,5 +147,4 @@ public function test_should_fall_back_to_single_file_copy_when_source_and_destin $this->assertTrue( $actual ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php index 5e458a3b7c1bc..57d6f92bbc6f6 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/mtime.php @@ -65,5 +65,4 @@ public function test_should_not_determine_file_modified_time( $path ) { 'The mtime is an integer.' ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/putContents.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/putContents.php index 13f12072ff7bd..8eabfffdb2f6a 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/putContents.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/putContents.php @@ -39,5 +39,4 @@ public function test_should_insert_contents_into_file() { $this->assertTrue( $actual, 'The contents were not inserted.' ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php index 3de09fe5cc9c9..9186fcf2e03ce 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/rmdir.php @@ -197,5 +197,4 @@ public function test_should_return_false_when_path_exists_but_is_not_a_file_or_d $this->assertFalse( $actual ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php index 39f68e55c8166..8870b8ac8cdec 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/size.php @@ -60,5 +60,4 @@ public function test_should_not_determine_file_size( $path ) { 'A file size was determined.' ); } - } diff --git a/tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php b/tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php index c0eddad6a815a..6fc494479c61f 100644 --- a/tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php +++ b/tests/phpunit/tests/filesystem/wpFilesystemDirect/touch.php @@ -90,5 +90,4 @@ public function data_should_create_file() { ), ); } - }