WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2014 07:05:52 PM (5 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r30526 r30658  
    484484    }
    485485
     486    function delete_folders( $path ) {
     487        $this->matched_dirs = array();
     488        if ( ! is_dir( $path ) ) {
     489            return;
     490        }
     491
     492        $this->scandir( $path );
     493        foreach ( array_reverse( $this->matched_dirs ) as $dir ) {
     494            rmdir( $dir );
     495        }
     496        rmdir( $path );
     497    }
     498
     499    function scandir( $dir ) {
     500        foreach ( scandir( $dir ) as $path ) {
     501            if ( 0 !== strpos( $path, '.' ) && is_dir( $dir . '/' . $path ) ) {
     502                $this->matched_dirs[] = $dir . '/' . $path;
     503                $this->scandir( $dir . '/' . $path );
     504            }
     505        }
     506    }
     507
    486508    /**
    487509     * Helper to Convert a microtime string into a float
Note: See TracChangeset for help on using the changeset viewer.