Skip to content

Commit

Permalink
Tests: Revert removing empty directory in `WP_UnitTestCase_Base::rmdi…
Browse files Browse the repository at this point in the history
…r()` 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
  • Loading branch information
SergeyBiryukov authored and = committed Nov 4, 2022
1 parent 2898df0 commit 0117bbc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
13 changes: 0 additions & 13 deletions tests/phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1350,29 +1350,16 @@ public function unlink( $file ) {
* 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 );
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/multisite/cleanDirsizeCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ public function test_5_5_transient_structure_compat() {

// Cleanup.
$this->remove_added_uploads();
rmdir( $upload_dir['basedir'] . '/2/1' );

restore_current_blog();
}

Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/tests/rest-api/rest-plugins-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ public static function wpTearDownAfterClass() {

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' ) ) {
unlink( DIR_TESTDATA . '/link-manager.zip' );
}

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();
Expand Down

0 comments on commit 0117bbc

Please sign in to comment.