💦 FULL SET: Changeset/ - Collection

Changeset 48464


Ignore:
Timestamp:
07/14/2020 01:28:17 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Tests: Replace hardcoded /tmp/ references with get_temp_dir().

This allows more tests to pass on Windows.

Props danielhuesken, DJPaul, christophherr, joemcgill, netweb, davidbaumwald, SergeyBiryukov.
Fixes #40856, #39975.

Location:
trunk/tests/phpunit
Files:
10 edited

Legend:

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

    r47880 r48464  
    914914        $tmp_dir = '';
    915915        $dirs    = array( 'TMP', 'TMPDIR', 'TEMP' );
     916
    916917        foreach ( $dirs as $dir ) {
    917918            if ( isset( $_ENV[ $dir ] ) && ! empty( $_ENV[ $dir ] ) ) {
     
    920921            }
    921922        }
     923
    922924        if ( empty( $tmp_dir ) ) {
    923             $tmp_dir = '/tmp';
    924         }
     925            $tmp_dir = get_temp_dir();
     926        }
     927
    925928        $tmp_dir = realpath( $tmp_dir );
     929
    926930        return tempnam( $tmp_dir, 'wpunit' );
    927931    }
  • trunk/tests/phpunit/tests/customize/manager.php

    r48438 r48464  
    6161
    6262        $orig_file       = DIR_TESTDATA . '/images/canola.jpg';
    63         $this->test_file = '/tmp/canola.jpg';
     63        $this->test_file = get_temp_dir() . 'canola.jpg';
    6464        copy( $orig_file, $this->test_file );
    6565        $orig_file2       = DIR_TESTDATA . '/images/waffles.jpg';
    66         $this->test_file2 = '/tmp/waffles.jpg';
     66        $this->test_file2 = get_temp_dir() . 'waffles.jpg';
    6767        copy( $orig_file2, $this->test_file2 );
    6868    }
  • trunk/tests/phpunit/tests/file.php

    r47122 r48464  
    99        parent::setUp();
    1010
    11         $file      = tempnam( '/tmp', 'foo' );
    12         $this->dir = dirname( $file );
    13         unlink( $file );
     11        $this->dir = untrailingslashit( get_temp_dir() );
    1412
    1513        $this->badchars = '"\'[]*&?$';
  • trunk/tests/phpunit/tests/image/functions.php

    r48454 r48464  
    2121
    2222        // Ensure no legacy / failed tests detritus.
    23         $folder = '/tmp/wordpress-gsoc-flyer*.{jpg,pdf}';
     23        $folder = get_temp_dir() . 'wordpress-gsoc-flyer*.{jpg,pdf}';
    2424
    2525        foreach ( glob( $folder, GLOB_BRACE ) as $file ) {
     
    426426
    427427        $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf';
    428         $test_file = '/tmp/wordpress-gsoc-flyer.pdf';
     428        $test_file = get_temp_dir() . 'wordpress-gsoc-flyer.pdf';
    429429        copy( $orig_file, $test_file );
    430430
     
    477477
    478478        unlink( $test_file );
     479        $temp_dir = get_temp_dir();
    479480        foreach ( $metadata['sizes'] as $size ) {
    480             unlink( '/tmp/' . $size['file'] );
     481            unlink( $temp_dir . $size['file'] );
    481482        }
    482483    }
     
    561562
    562563        $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf';
    563         $test_file = '/tmp/wordpress-gsoc-flyer.pdf';
     564        $test_file = get_temp_dir() . 'wordpress-gsoc-flyer.pdf';
    564565        copy( $orig_file, $test_file );
    565566
     
    597598
    598599        unlink( $test_file );
     600        $temp_dir = get_temp_dir();
    599601        foreach ( $metadata['sizes'] as $size ) {
    600             unlink( '/tmp/' . $size['file'] );
     602            unlink( $temp_dir . $size['file'] );
    601603        }
    602604    }
     
    619621        }
    620622
     623        $temp_dir = get_temp_dir();
     624
    621625        // Dummy JPEGs.
    622         $jpg1_path = '/tmp/test.jpg'; // Straight.
     626        $jpg1_path = $temp_dir . 'test.jpg'; // Straight.
    623627        file_put_contents( $jpg1_path, 'asdf' );
    624         $jpg2_path = '/tmp/test-pdf.jpg'; // With PDF marker.
     628        $jpg2_path = $temp_dir . 'test-pdf.jpg'; // With PDF marker.
    625629        file_put_contents( $jpg2_path, 'fdsa' );
    626630
    627631        // PDF with same name as JPEG.
    628         $pdf_path = '/tmp/test.pdf';
     632        $pdf_path = $temp_dir . 'test.pdf';
    629633        copy( DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf', $pdf_path );
    630634
     
    643647
    644648        $metadata     = wp_generate_attachment_metadata( $attachment_id, $pdf_path );
    645         $preview_path = '/tmp/' . $metadata['sizes']['full']['file'];
     649        $preview_path = $temp_dir . $metadata['sizes']['full']['file'];
    646650
    647651        // PDF preview didn't overwrite PDF.
     
    659663        unlink( $pdf_path );
    660664        foreach ( $metadata['sizes'] as $size ) {
    661             unlink( '/tmp/' . $size['file'] );
     665            unlink( $temp_dir . $size['file'] );
    662666        }
    663667