Make WordPress Core

Changeset 59604


Ignore:
Timestamp:
01/14/2025 03:35:18 PM (20 months ago)
Author:
SergeyBiryukov
Message:

Tests: Restore the environment before performing assertions in download_url() tests.

This aims to avoid affecting other tests in case of failure.

Follow-up to [42773], [51939].

See #62280.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesFile.php

    r59061 r59604  
    4444
    4545                $error = download_url( 'test_download_url_non_200' );
     46
    4647                $this->assertWPError( $error );
    4748                $this->assertSame(
     
    5657
    5758                $error = download_url( 'test_download_url_non_200' );
     59
     60                remove_filter( 'download_url_error_max_body_size', array( $this, '__return_5' ) );
     61                remove_filter( 'pre_http_request', array( $this, '_fake_download_url_non_200_response_code' ) );
     62
    5863                $this->assertWPError( $error );
    5964                $this->assertSame(
     
    6469                        $error->get_error_data()
    6570                );
    66 
    67                 remove_filter( 'download_url_error_max_body_size', array( $this, '__return_5' ) );
    68                 remove_filter( 'pre_http_request', array( $this, '_fake_download_url_non_200_response_code' ) );
    6971        }
    7072
     
    9597
    9698                $filename = download_url( 'url_with_content_disposition_header' );
    97                 $this->assertStringContainsString( 'filename-from-content-disposition-header', $filename );
     99
     100                remove_filter( 'pre_http_request', array( $this, $filter ) );
     101
    98102                $this->assertFileExists( $filename );
    99103                $this->unlink( $filename );
    100104
    101                 remove_filter( 'pre_http_request', array( $this, $filter ) );
     105                $this->assertStringContainsString( 'filename-from-content-disposition-header', $filename );
    102106        }
    103107
     
    127131
    128132                $filename = download_url( 'url_with_content_disposition_header' );
     133
     134                remove_filter( 'pre_http_request', array( $this, $filter ) );
     135
     136                $this->unlink( $filename );
     137
    129138                $this->assertStringContainsString( get_temp_dir(), $filename );
    130                 $this->unlink( $filename );
    131 
    132                 remove_filter( 'pre_http_request', array( $this, $filter ) );
    133139        }
    134140
     
    210216
    211217                $filename = download_url( 'url_with_content_disposition_header' );
     218
     219                remove_filter( 'pre_http_request', array( $this, $filter ) );
     220
     221                $this->unlink( $filename );
     222
    212223                $this->assertStringContainsString( 'url_with_content_disposition_header', $filename );
    213                 $this->unlink( $filename );
    214 
    215                 remove_filter( 'pre_http_request', array( $this, $filter ) );
    216224        }
    217225
Note: See TracChangeset for help on using the changeset viewer.