nextcloud/tests/lib/AppFramework/Http/DownloadResponseTest.php

60 lines
2 KiB
PHP
Raw Permalink Normal View History

2013-08-17 05:16:48 -04:00
<?php
/**
* 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;
class ChildDownloadResponse extends DownloadResponse {
};
2013-08-17 05:16:48 -04:00
class DownloadResponseTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
2013-08-17 05:16:48 -04:00
}
public function testHeaders(): void {
$response = new ChildDownloadResponse('file', 'content');
$headers = $response->getHeaders();
$this->assertEquals('attachment; filename=file', $headers['Content-Disposition']);
$this->assertEquals('content', $headers['Content-Type']);
}
#[\PHPUnit\Framework\Attributes\DataProvider('filenameEncodingProvider')]
public function testFilenameEncoding(string $input, string $expectedDisposition): void {
$response = new ChildDownloadResponse($input, 'content');
$headers = $response->getHeaders();
$this->assertEquals($expectedDisposition, $headers['Content-Disposition']);
}
2013-08-17 05:16:48 -04:00
public static function filenameEncodingProvider(): array {
return [
['TestName.txt', 'attachment; filename=TestName.txt'],
['A "Quoted" Filename.txt', 'attachment; filename="A \"Quoted\" Filename.txt"'],
['A "Quoted" Filename.txt', 'attachment; filename="A \"Quoted\" Filename.txt"'],
['A "Quoted" Filename With A Backslash \\.txt', 'attachment; filename="A \"Quoted\" Filename With A Backslash -.txt"'],
['A "Very" Weird Filename \ / & <> " >\'""""\.text', 'attachment; filename="A \"Very\" Weird Filename - - & <> \" >\'\"\"\"\"-.text"'],
['\\\\\\\\\\\\', 'attachment; filename=------'],
];
2013-08-17 05:16:48 -04:00
}
public function testSpecialCharactersInFilename(): void {
$filename = 'document "draft" with; special&chars.pdf';
$response = new ChildDownloadResponse($filename, 'application/pdf');
$headers = $response->getHeaders();
$this->assertEquals(
'attachment; filename="document \"draft\" with; special&chars.pdf"',
$headers['Content-Disposition']
);
}
2013-08-17 05:16:48 -04:00
}