2013-08-17 05:16:48 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2013-08-17 05:16:48 -04:00
|
|
|
*/
|
|
|
|
|
|
2016-05-18 12:40:34 -04:00
|
|
|
namespace Test\AppFramework\Http;
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2016-05-18 12:40:34 -04:00
|
|
|
use OCP\AppFramework\Http\DownloadResponse;
|
|
|
|
|
|
2014-10-30 12:20:40 -04:00
|
|
|
class ChildDownloadResponse extends DownloadResponse {
|
|
|
|
|
};
|
2013-08-17 05:16:48 -04:00
|
|
|
|
|
|
|
|
|
2014-11-10 17:30:38 -05:00
|
|
|
class DownloadResponseTest extends \Test\TestCase {
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2014-11-10 17:30:38 -05:00
|
|
|
parent::setUp();
|
2013-08-17 05:16:48 -04:00
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testHeaders(): void {
|
2021-06-02 12:59:43 -04:00
|
|
|
$response = new ChildDownloadResponse('file', 'content');
|
|
|
|
|
$headers = $response->getHeaders();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('attachment; filename="file"', $headers['Content-Disposition']);
|
|
|
|
|
$this->assertEquals('content', $headers['Content-Type']);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('filenameEncodingProvider')]
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testFilenameEncoding(string $input, string $expected): void {
|
2021-06-02 12:59:43 -04:00
|
|
|
$response = new ChildDownloadResponse($input, 'content');
|
|
|
|
|
$headers = $response->getHeaders();
|
|
|
|
|
|
2024-09-19 05:10:31 -04:00
|
|
|
$this->assertEquals('attachment; filename="' . $expected . '"', $headers['Content-Disposition']);
|
2021-06-02 12:59:43 -04:00
|
|
|
}
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2025-05-12 11:18:04 -04:00
|
|
|
public static function filenameEncodingProvider() : array {
|
2021-06-02 12:59:43 -04:00
|
|
|
return [
|
|
|
|
|
['TestName.txt', 'TestName.txt'],
|
|
|
|
|
['A "Quoted" Filename.txt', 'A \\"Quoted\\" Filename.txt'],
|
|
|
|
|
['A "Quoted" Filename.txt', 'A \\"Quoted\\" Filename.txt'],
|
|
|
|
|
['A "Quoted" Filename With A Backslash \\.txt', 'A \\"Quoted\\" Filename With A Backslash \\\\.txt'],
|
|
|
|
|
['A "Very" Weird Filename \ / & <> " >\'""""\.text', 'A \\"Very\\" Weird Filename \\\\ / & <> \\" >\'\\"\\"\\"\\"\\\\.text'],
|
|
|
|
|
['\\\\\\\\\\\\', '\\\\\\\\\\\\\\\\\\\\\\\\'],
|
|
|
|
|
];
|
2013-08-17 05:16:48 -04:00
|
|
|
}
|
|
|
|
|
}
|