Make WordPress Core


Ignore:
Timestamp:
11/30/2014 07:05:52 PM (9 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/tests/upload.php

    r29120 r30658  
    11<?php
    2 
    3 
    42/**
    53 * @group upload
     
    119
    1210    function setUp() {
    13         if ( is_multisite() )
     11        if ( is_multisite() ) {
    1412            $this->knownUTBug( 35 );
     13        }
    1514
     15        $this->_reset_options();
    1616        parent::setUp();
    17         return;
     17    }
     18
     19    function _reset_options() {
    1820        // system defaults
    1921        update_option( 'upload_path', 'wp-content/uploads' );
    2022        update_option( 'upload_url_path', '' );
    2123        update_option( 'uploads_use_yearmonth_folders', 1 );
    22     }
    23 
    24     function tearDown() {
    25         $this->remove_added_uploads();
    26 
    27         parent::tearDown();
    2824    }
    2925
     
    4137        update_option( 'upload_path', 'foo/bar' );
    4238        $info = wp_upload_dir();
     39        $this->delete_folders( ABSPATH . 'foo' );
     40
    4341        $this->assertEquals( get_option( 'siteurl' ) . '/foo/bar/' . gmstrftime('%Y/%m'), $info['url'] );
    4442        $this->assertEquals( ABSPATH . 'foo/bar/' . gmstrftime('%Y/%m'), $info['path'] );
     
    5755        update_option( 'upload_url_path', '/baz' );
    5856        $info = wp_upload_dir();
     57        $this->delete_folders( $path );
     58
    5959        $this->assertEquals( '/baz/' . gmstrftime('%Y/%m'), $info['url'] );
    6060        $this->assertEquals( "$path/" . gmstrftime('%Y/%m'), $info['path'] );
Note: See TracChangeset for help on using the changeset viewer.