| 80 | |
| 81 | /** |
| 82 | * @ticket 38231 |
| 83 | * @dataProvider provider_for_download_url_filename_from_content_disposition_header |
| 84 | */ |
| 85 | public function test_download_url_filename_from_content_disposition_header( $filter ) { |
| 86 | add_filter( 'pre_http_request', array( $this, $filter ), 10, 3 ); |
| 87 | |
| 88 | $filename = download_url( 'url_with_content_disposition_header' ); |
| 89 | $this->assertContains( 'filename-from-content-disposition-header', $filename ); |
| 90 | $this->assertFileExists( $filename ); |
| 91 | $this->unlink( $filename ); |
| 92 | |
| 93 | remove_filter( 'pre_http_request', array( $this, $filter ) ); |
| 94 | } |
| 95 | |
| 96 | public function provider_for_download_url_filename_from_content_disposition_header() { |
| 97 | return array( |
| 98 | array( '_fake_download_url_with_content_disposition_header' ), |
| 99 | array( '_fake_download_url_with_content_disposition_header_without_quotes' ), |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | public function _fake_download_url_with_content_disposition_header( $response, $args, $url ) { |
| 104 | return array( |
| 105 | 'response' => array( |
| 106 | 'code' => 200, |
| 107 | ), |
| 108 | 'headers' => array( |
| 109 | 'Content-Disposition' => 'filename="filename-from-content-disposition-header.txt"', |
| 110 | ), |
| 111 | ); |
| 112 | } |
| 113 | |
| 114 | public function _fake_download_url_with_content_disposition_header_without_quotes( $response, $args, $url ) { |
| 115 | return array( |
| 116 | 'response' => array( |
| 117 | 'code' => 200, |
| 118 | ), |
| 119 | 'headers' => array( |
| 120 | 'Content-Disposition' => 'filename=filename-from-content-disposition-header.txt', |
| 121 | ), |
| 122 | ); |
| 123 | } |