WordPress.org

Make WordPress Core

Ticket #38231: 38231-tests.diff

File 38231-tests.diff, 1.2 KB (added by psrpinto, 4 months ago)

Unit tests

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

    diff --git tests/phpunit/tests/admin/includesFile.php tests/phpunit/tests/admin/includesFile.php
    index a3af5da2d1..15da2a2e4f 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                $this->unlink( $filename );
     89
     90                $this->assertContains( 'filename-from-content-disposition-header', $filename );
     91
     92                remove_filter( 'pre_http_request', array( $this, '_fake_download_url_with_content_disposition_header' ) );
     93        }
     94
     95        public function _fake_download_url_with_content_disposition_header( $response, $args, $url ) {
     96                return array(
     97                        'response' => array(
     98                                'code' => 200,
     99                        ),
     100                        'headers'  => array(
     101                                'Content-Disposition' => 'filename="filename-from-content-disposition-header.txt"',
     102                        ),
     103                );
     104        }
    80105}