DownloadResponseTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Test\AppFramework\Http;
  23. use OCP\AppFramework\Http\DownloadResponse;
  24. class ChildDownloadResponse extends DownloadResponse {
  25. };
  26. class DownloadResponseTest extends \Test\TestCase {
  27. protected function setUp(): void {
  28. parent::setUp();
  29. }
  30. public function testHeaders() {
  31. $response = new ChildDownloadResponse('file', 'content');
  32. $headers = $response->getHeaders();
  33. $this->assertEquals('attachment; filename="file"', $headers['Content-Disposition']);
  34. $this->assertEquals('content', $headers['Content-Type']);
  35. }
  36. /**
  37. * @dataProvider filenameEncodingProvider
  38. */
  39. public function testFilenameEncoding(string $input, string $expected) {
  40. $response = new ChildDownloadResponse($input, 'content');
  41. $headers = $response->getHeaders();
  42. $this->assertEquals('attachment; filename="'.$expected.'"', $headers['Content-Disposition']);
  43. }
  44. public function filenameEncodingProvider() : array {
  45. return [
  46. ['TestName.txt', 'TestName.txt'],
  47. ['A "Quoted" Filename.txt', 'A \\"Quoted\\" Filename.txt'],
  48. ['A "Quoted" Filename.txt', 'A \\"Quoted\\" Filename.txt'],
  49. ['A "Quoted" Filename With A Backslash \\.txt', 'A \\"Quoted\\" Filename With A Backslash \\\\.txt'],
  50. ['A "Very" Weird Filename \ / & <> " >\'""""\.text', 'A \\"Very\\" Weird Filename \\\\ / & <> \\" >\'\\"\\"\\"\\"\\\\.text'],
  51. ['\\\\\\\\\\\\', '\\\\\\\\\\\\\\\\\\\\\\\\'],
  52. ];
  53. }
  54. }