DownloadResponseTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\AppFramework\Http;
  8. use OCP\AppFramework\Http\DownloadResponse;
  9. class ChildDownloadResponse extends DownloadResponse {
  10. };
  11. class DownloadResponseTest extends \Test\TestCase {
  12. protected function setUp(): void {
  13. parent::setUp();
  14. }
  15. public function testHeaders(): void {
  16. $response = new ChildDownloadResponse('file', 'content');
  17. $headers = $response->getHeaders();
  18. $this->assertEquals('attachment; filename="file"', $headers['Content-Disposition']);
  19. $this->assertEquals('content', $headers['Content-Type']);
  20. }
  21. /**
  22. * @dataProvider filenameEncodingProvider
  23. */
  24. public function testFilenameEncoding(string $input, string $expected): void {
  25. $response = new ChildDownloadResponse($input, 'content');
  26. $headers = $response->getHeaders();
  27. $this->assertEquals('attachment; filename="'.$expected.'"', $headers['Content-Disposition']);
  28. }
  29. public function filenameEncodingProvider() : array {
  30. return [
  31. ['TestName.txt', 'TestName.txt'],
  32. ['A "Quoted" Filename.txt', 'A \\"Quoted\\" Filename.txt'],
  33. ['A "Quoted" Filename.txt', 'A \\"Quoted\\" Filename.txt'],
  34. ['A "Quoted" Filename With A Backslash \\.txt', 'A \\"Quoted\\" Filename With A Backslash \\\\.txt'],
  35. ['A "Very" Weird Filename \ / & <> " >\'""""\.text', 'A \\"Very\\" Weird Filename \\\\ / & <> \\" >\'\\"\\"\\"\\"\\\\.text'],
  36. ['\\\\\\\\\\\\', '\\\\\\\\\\\\\\\\\\\\\\\\'],
  37. ];
  38. }
  39. }