mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-30 23:30:05 +00:00
wp_upload_dir() has a (little-known?) side effect: if you call it, it will attempt to create an uploads directory for the current month. As such, tearDown() and cleanup routines have to be in sync with this behavior when deleting bogus directories used in unit tests.
Examples: if you clean up directories in a test, or a test fails before the directories are cleaned, or a test fails before the `'upload_path'` option is reset, the next call to `wp_upload_dir()` will recreate the directories you just tried to delete. These changes ensure that `src/foo` and `/tmp/wp-unit-test` directories are deleted immediately after `wp_upload_dir()` is fired in the tests. Fixes #30513. git-svn-id: https://develop.svn.wordpress.org/trunk@30658 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -483,6 +483,28 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
|
||||
return $files;
|
||||
}
|
||||
|
||||
function delete_folders( $path ) {
|
||||
$this->matched_dirs = array();
|
||||
if ( ! is_dir( $path ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->scandir( $path );
|
||||
foreach ( array_reverse( $this->matched_dirs ) as $dir ) {
|
||||
rmdir( $dir );
|
||||
}
|
||||
rmdir( $path );
|
||||
}
|
||||
|
||||
function scandir( $dir ) {
|
||||
foreach ( scandir( $dir ) as $path ) {
|
||||
if ( 0 !== strpos( $path, '.' ) && is_dir( $dir . '/' . $path ) ) {
|
||||
$this->matched_dirs[] = $dir . '/' . $path;
|
||||
$this->scandir( $dir . '/' . $path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to Convert a microtime string into a float
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user