Make WordPress Core

Ticket #38231: 38231-tests.1.diff

File 38231-tests.1.diff, 1.2 KB (added by psrpinto, 3 years ago)

Test that the file is actually created

  • tests/phpunit/tests/admin/includesFile.php

    diff --git tests/phpunit/tests/admin/includesFile.php tests/phpunit/tests/admin/includesFile.php
    index a3af5da2d1..94549354fb 100644
    class Tests_Admin_includesFile extends WP_UnitTestCase { 
    7777        public function __return_5() {
    7878                return 5;
    7979        }
     80
     81        /**
     82         * @ticket 38231
     83         */
     84        public function test_download_url_filename_from_content_disposition_header() {
     85                add_filter( 'pre_http_request', array( $this, '_fake_download_url_with_content_disposition_header' ), 10, 3 );
     86
     87                $filename = download_url( 'url_with_content_disposition_header' );
     88
     89                $this->assertContains( 'filename-from-content-disposition-header', $filename );
     90                $this->assertFileExists( $filename );
     91
     92                $this->unlink( $filename );
     93
     94                remove_filter( 'pre_http_request', array( $this, '_fake_download_url_with_content_disposition_header' ) );
     95        }
     96
     97        public function _fake_download_url_with_content_disposition_header( $response, $args, $url ) {
     98                return array(
     99                        'response' => array(
     100                                'code' => 200,
     101                        ),
     102                        'headers'  => array(
     103                                'Content-Disposition' => 'filename="filename-from-content-disposition-header.txt"',
     104                        ),
     105                );
     106        }
    80107}