locking.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. * @author Robin Appelman <icewind@owncloud.com>
  5. * @author Vincent Petry <pvince81@owncloud.com>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Files_sharing\Tests;
  24. use OC\Files\Filesystem;
  25. use OC\Files\View;
  26. use OC\Lock\MemcacheLockingProvider;
  27. use OCP\Lock\ILockingProvider;
  28. class Locking extends TestCase {
  29. /**
  30. * @var \Test\Util\User\Dummy
  31. */
  32. private $userBackend;
  33. private $ownerUid;
  34. private $recipientUid;
  35. public function setUp() {
  36. parent::setUp();
  37. $this->userBackend = new \Test\Util\User\Dummy();
  38. \OC::$server->getUserManager()->registerBackend($this->userBackend);
  39. $this->ownerUid = $this->getUniqueID('owner_');
  40. $this->recipientUid = $this->getUniqueID('recipient_');
  41. $this->userBackend->createUser($this->ownerUid, '');
  42. $this->userBackend->createUser($this->recipientUid, '');
  43. $this->loginAsUser($this->ownerUid);
  44. Filesystem::mkdir('/foo');
  45. Filesystem::file_put_contents('/foo/bar.txt', 'asd');
  46. $fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
  47. \OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31);
  48. $this->loginAsUser($this->recipientUid);
  49. $this->assertTrue(Filesystem::file_exists('bar.txt'));
  50. }
  51. public function tearDown() {
  52. \OC::$server->getUserManager()->removeBackend($this->userBackend);
  53. parent::tearDown();
  54. }
  55. /**
  56. * @expectedException \OCP\Lock\LockedException
  57. */
  58. public function testLockAsRecipient() {
  59. $this->loginAsUser($this->ownerUid);
  60. Filesystem::initMountPoints($this->recipientUid);
  61. $recipientView = new View('/' . $this->recipientUid . '/files');
  62. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  63. Filesystem::rename('/foo', '/asd');
  64. }
  65. public function testUnLockAsRecipient() {
  66. $this->loginAsUser($this->ownerUid);
  67. Filesystem::initMountPoints($this->recipientUid);
  68. $recipientView = new View('/' . $this->recipientUid . '/files');
  69. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  70. $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  71. $this->assertTrue(Filesystem::rename('/foo', '/asd'));
  72. }
  73. public function testChangeLock() {
  74. Filesystem::initMountPoints($this->recipientUid);
  75. $recipientView = new View('/' . $this->recipientUid . '/files');
  76. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED);
  77. $recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  78. $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  79. $this->assertTrue(true);
  80. }
  81. }