From 8f3254d794ca4e8b8e0ec8254e5886be840a60c6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 25 Sep 2022 04:47:02 +0000 Subject: [PATCH] Tests: Revert removing empty directory in `WP_UnitTestCase_Base::rmdir()` for now. This appears to need more investigation. Instead, delete the `test-plugin` and `link-manager` directories in REST API plugins controller tests, for which this change was initially intended. Follow-up to [54300], [54301], [54303]. See #55652, #56629. git-svn-id: https://develop.svn.wordpress.org/trunk@54304 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 13 ------------- tests/phpunit/tests/multisite/cleanDirsizeCache.php | 2 ++ .../tests/rest-api/rest-plugins-controller.php | 6 ++++++ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index fa667f99ba..1a60c630f1 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1350,29 +1350,16 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { * Does not delete files if their paths are set in the `$ignore_files` property. * * @since 4.0.0 - * @since 6.1.0 Removes the empty directory if there are no files left. * * @param string $path Directory path. */ public function rmdir( $path ) { - if ( ! is_dir( $path ) ) { - return; - } - $files = $this->files_in_dir( $path ); foreach ( $files as $file ) { if ( ! in_array( $file, self::$ignore_files, true ) ) { $this->unlink( $file ); } } - - /* - * If there were no ignored files, remove the empty directory. - * If there are any nested empty directories, remove them too. - */ - if ( ! array_intersect( $files, self::$ignore_files ) ) { - $this->delete_folders( $path ); - } } /** diff --git a/tests/phpunit/tests/multisite/cleanDirsizeCache.php b/tests/phpunit/tests/multisite/cleanDirsizeCache.php index a777feca8a..df38ee33d1 100644 --- a/tests/phpunit/tests/multisite/cleanDirsizeCache.php +++ b/tests/phpunit/tests/multisite/cleanDirsizeCache.php @@ -295,6 +295,8 @@ if ( is_multisite() ) : // Cleanup. $this->remove_added_uploads(); + rmdir( $upload_dir['basedir'] . '/2/1' ); + restore_current_blog(); } diff --git a/tests/phpunit/tests/rest-api/rest-plugins-controller.php b/tests/phpunit/tests/rest-api/rest-plugins-controller.php index 60b74ddd28..3143c6a761 100644 --- a/tests/phpunit/tests/rest-api/rest-plugins-controller.php +++ b/tests/phpunit/tests/rest-api/rest-plugins-controller.php @@ -84,7 +84,10 @@ class WP_REST_Plugins_Controller_Test extends WP_Test_REST_Controller_Testcase { public function tear_down() { if ( file_exists( WP_PLUGIN_DIR . '/test-plugin/test-plugin.php' ) ) { + // Remove plugin files. $this->rmdir( WP_PLUGIN_DIR . '/test-plugin' ); + // Delete empty directory. + rmdir( WP_PLUGIN_DIR . '/test-plugin' ); } if ( file_exists( DIR_TESTDATA . '/link-manager.zip' ) ) { @@ -92,7 +95,10 @@ class WP_REST_Plugins_Controller_Test extends WP_Test_REST_Controller_Testcase { } if ( file_exists( WP_PLUGIN_DIR . '/link-manager/link-manager.php' ) ) { + // Remove plugin files. $this->rmdir( WP_PLUGIN_DIR . '/link-manager' ); + // Delete empty directory. + rmdir( WP_PLUGIN_DIR . '/link-manager' ); } parent::tear_down();