WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/16/2019 11:22:00 PM (18 months ago)
Author:
azaozz
Message:

Upload:

  • Fix PHP warnings in wp_unique_filename() when the destination directory is unreadable.
  • Run the final name collision test only for files that are saved to the uploads directory.
  • Update the unit tests to match.

Props eden159, audrasjb, azaozz.
Fixes #48960 for trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions.php

    r46835 r46965  
    202202        $testdir = DIR_TESTDATA . '/images/';
    203203
     204        add_filter( 'upload_dir', array( $this, 'upload_dir_patch_basedir' ) );
     205
    204206        // Test collision with "dimension-like" original filename.
    205207        $this->assertEquals( 'one-blue-pixel-100x100-1.png', wp_unique_filename( $testdir, 'one-blue-pixel-100x100.png' ) );
     
    207209        // Existing files: one-blue-pixel-100x100.png, one-blue-pixel-1-100x100.png.
    208210        $this->assertEquals( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.png' ) );
     211
     212        remove_filter( 'upload_dir', array( $this, 'upload_dir_patch_basedir' ) );
     213    }
     214
     215    // Callback to patch "basedir" when used in `wp_unique_filename()`.
     216    function upload_dir_patch_basedir( $upload_dir ) {
     217        $upload_dir['basedir'] = DIR_TESTDATA . '/images/';
     218        return $upload_dir;
    209219    }
    210220
     
    229239            ),
    230240        );
     241
    231242        foreach ( $cases as $case ) {
    232243            $this->assertTrue( is_serialized( $case ), "Serialized data: $case" );
     
    238249            's:4:test;',
    239250        );
     251
    240252        foreach ( $not_serialized as $case ) {
    241253            $this->assertFalse( is_serialized( $case ), "Test data: $case" );
Note: See TracChangeset for help on using the changeset viewer.