DownloadTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
  26. use OCP\AppFramework\Http;
  27. use OCP\Lock\ILockingProvider;
  28. /**
  29. * Class DownloadTest
  30. *
  31. * @group DB
  32. *
  33. * @package OCA\DAV\Tests\unit\Connector\Sabre\RequestTest
  34. */
  35. class DownloadTest extends RequestTestCase {
  36. public function testDownload(): void {
  37. $user = $this->getUniqueID();
  38. $view = $this->setupUser($user, 'pass');
  39. $view->file_put_contents('foo.txt', 'bar');
  40. $response = $this->request($view, $user, 'pass', 'GET', '/foo.txt');
  41. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  42. $this->assertEquals(stream_get_contents($response->getBody()), 'bar');
  43. }
  44. public function testDownloadWriteLocked(): void {
  45. $user = $this->getUniqueID();
  46. $view = $this->setupUser($user, 'pass');
  47. $view->file_put_contents('foo.txt', 'bar');
  48. $view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);
  49. $result = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
  50. $this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
  51. }
  52. public function testDownloadReadLocked(): void {
  53. $user = $this->getUniqueID();
  54. $view = $this->setupUser($user, 'pass');
  55. $view->file_put_contents('foo.txt', 'bar');
  56. $view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);
  57. $response = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
  58. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  59. $this->assertEquals(stream_get_contents($response->getBody()), 'bar');
  60. }
  61. }