DownloadTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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-only
  6. */
  7. namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
  8. use OCP\AppFramework\Http;
  9. use OCP\Lock\ILockingProvider;
  10. /**
  11. * Class DownloadTest
  12. *
  13. * @group DB
  14. *
  15. * @package OCA\DAV\Tests\unit\Connector\Sabre\RequestTest
  16. */
  17. class DownloadTest extends RequestTestCase {
  18. public function testDownload(): void {
  19. $user = $this->getUniqueID();
  20. $view = $this->setupUser($user, 'pass');
  21. $view->file_put_contents('foo.txt', 'bar');
  22. $response = $this->request($view, $user, 'pass', 'GET', '/foo.txt');
  23. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  24. $this->assertEquals(stream_get_contents($response->getBody()), 'bar');
  25. }
  26. public function testDownloadWriteLocked(): void {
  27. $user = $this->getUniqueID();
  28. $view = $this->setupUser($user, 'pass');
  29. $view->file_put_contents('foo.txt', 'bar');
  30. $view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);
  31. $result = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
  32. $this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
  33. }
  34. public function testDownloadReadLocked(): void {
  35. $user = $this->getUniqueID();
  36. $view = $this->setupUser($user, 'pass');
  37. $view->file_put_contents('foo.txt', 'bar');
  38. $view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);
  39. $response = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
  40. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  41. $this->assertEquals(stream_get_contents($response->getBody()), 'bar');
  42. }
  43. }