Make WordPress Core

Changeset 48464


Ignore:
Timestamp:
07/14/2020 01:28:17 AM (6 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        }
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r48291 r48464  
    8181
    8282                $orig_file       = DIR_TESTDATA . '/images/canola.jpg';
    83                 $this->test_file = '/tmp/canola.jpg';
     83                $this->test_file = get_temp_dir() . 'canola.jpg';
    8484                copy( $orig_file, $this->test_file );
    8585                $orig_file2       = DIR_TESTDATA . '/images/codeispoetry.png';
    86                 $this->test_file2 = '/tmp/codeispoetry.png';
     86                $this->test_file2 = get_temp_dir() . 'codeispoetry.png';
    8787                copy( $orig_file2, $this->test_file2 );
    8888        }
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r48291 r48464  
    227227
    228228                $media_id = $this->factory->attachment->create_object(
    229                         '/tmp/canola.jpg',
     229                        get_temp_dir() . 'canola.jpg',
    230230                        0,
    231231                        array(
  • trunk/tests/phpunit/tests/upload.php

    r47122 r48464  
    4747         */
    4848        function test_upload_dir_absolute() {
    49                 $path = '/tmp/wp-unit-test';
     49                $path = get_temp_dir() . 'wp-unit-test';
    5050
    5151                // wp_upload_dir() with an absolute upload path.
  • trunk/tests/phpunit/tests/widgets/media-gallery-widget.php

    r46586 r48464  
    5959                $attachments = array();
    6060                foreach ( array( 'canola.jpg', 'waffles.jpg' ) as $filename ) {
    61                         $test_image = '/tmp/' . $filename;
     61                        $test_image = get_temp_dir() . $filename;
    6262                        copy( DIR_TESTDATA . '/images/canola.jpg', $test_image );
    6363                        $attachment_id = self::factory()->attachment->create_object(
  • trunk/tests/phpunit/tests/widgets/media-image-widget.php

    r46586 r48464  
    413413                $widget = new WP_Widget_Media_Image();
    414414
    415                 $test_image = '/tmp/canola.jpg';
     415                $test_image = get_temp_dir() . 'canola.jpg';
    416416                copy( DIR_TESTDATA . '/images/canola.jpg', $test_image );
    417417                $attachment_id = self::factory()->attachment->create_object(
  • trunk/tests/phpunit/tests/widgets/media-widget.php

    r46586 r48464  
    139139        function test_is_attachment_with_mime_type() {
    140140
    141                 $test_image = '/tmp/canola.jpg';
     141                $test_image = get_temp_dir() . 'canola.jpg';
    142142                copy( DIR_TESTDATA . '/images/canola.jpg', $test_image );
    143143                $attachment_id = self::factory()->attachment->create_object(
Note: See TracChangeset for help on using the changeset viewer.