diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-02 13:34:50 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-02 13:34:50 +0100 |
commit | ce053b980860070957bedb13e6fcd9d45fe50b9b (patch) | |
tree | 4d31c74f75d43629b815d4184e3f93be46f1cee1 /tests | |
parent | 2d1d89ee29e49412192b051412755610e0538198 (diff) | |
parent | 2316cb1f8b9704621b47e6eb1c2cbf30c06c552d (diff) | |
download | nextcloud-server-ce053b980860070957bedb13e6fcd9d45fe50b9b.tar.gz nextcloud-server-ce053b980860070957bedb13e6fcd9d45fe50b9b.zip |
Merge pull request #22013 from owncloud/share2_moveshare
[Share 2.0] Allow moving of shares
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/share20/defaultshareprovidertest.php | 69 | ||||
-rw-r--r-- | tests/lib/share20/managertest.php | 73 |
2 files changed, 142 insertions, 0 deletions
diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php index 4145e9e5ec6..504bd776036 100644 --- a/tests/lib/share20/defaultshareprovidertest.php +++ b/tests/lib/share20/defaultshareprovidertest.php @@ -1892,6 +1892,75 @@ class DefaultShareProviderTest extends \Test\TestCase { $stmt->closeCursor(); + } + + public function testMoveUserShare() { + $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_USER, 'user0', 'user1', 'user1', 'file', + 42, 'mytaret', 31, null, null); + + $user0 = $this->getMock('\OCP\IUser'); + $user0->method('getUID')->willReturn('user0'); + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + + $this->userManager->method('get')->will($this->returnValueMap([ + ['user0', $user0], + ['user1', $user1], + ])); + + $file = $this->getMock('\OCP\Files\File'); + $file->method('getId')->willReturn(42); + + $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); + $this->rootFolder->method('getById')->willReturn([$file]); + + $share = $this->provider->getShareById($id, null); + + $share->setTarget('/newTarget'); + $this->provider->move($share, $user0); + + $share = $this->provider->getShareById($id, null); + $this->assertSame('/newTarget', $share->getTarget()); + } + + public function testMoveGroupShare() { + $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1', 'file', + 42, 'mytaret', 31, null, null); + + $user0 = $this->getMock('\OCP\IUser'); + $user0->method('getUID')->willReturn('user0'); + $user1 = $this->getMock('\OCP\IUser'); + $user1->method('getUID')->willReturn('user1'); + + $group0 = $this->getMock('\OCP\IGroup'); + $group0->method('getGID')->willReturn('group0'); + $group0->method('inGroup')->with($user0)->willReturn(true); + + $this->groupManager->method('get')->with('group0')->willReturn($group0); + + $this->userManager->method('get')->will($this->returnValueMap([ + ['user0', $user0], + ['user1', $user1], + ])); + + $folder = $this->getMock('\OCP\Files\Folder'); + $folder->method('getId')->willReturn(42); + + $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); + $this->rootFolder->method('getById')->willReturn([$folder]); + + $share = $this->provider->getShareById($id, $user0); + + $share->setTarget('/newTarget'); + $this->provider->move($share, $user0); + + $share = $this->provider->getShareById($id, $user0); + $this->assertSame('/newTarget', $share->getTarget()); + + $share->setTarget('/ultraNewTarget'); + $this->provider->move($share, $user0); + $share = $this->provider->getShareById($id, $user0); + $this->assertSame('/ultraNewTarget', $share->getTarget()); } } diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index cdcb71ed1e5..6043d30a0bb 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -1908,6 +1908,79 @@ class ManagerTest extends \Test\TestCase { $manager->updateShare($share); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Can't change target of link share + */ + public function testMoveShareLink() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_LINK); + + $recipient = $this->getMock('\OCP\IUser'); + + $this->manager->moveShare($share, $recipient); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid recipient + */ + public function testMoveShareUserNotRecipient() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_USER); + + $sharedWith = $this->getMock('\OCP\IUser'); + $share->setSharedWith($sharedWith); + + $recipient = $this->getMock('\OCP\IUser'); + + $this->manager->moveShare($share, $recipient); + } + + public function testMoveShareUser() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_USER); + + $recipient = $this->getMock('\OCP\IUser'); + $share->setSharedWith($recipient); + + $this->defaultProvider->method('move')->with($share, $recipient)->will($this->returnArgument(0)); + + $this->manager->moveShare($share, $recipient); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid recipient + */ + public function testMoveShareGroupNotRecipient() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP); + + $sharedWith = $this->getMock('\OCP\IGroup'); + $share->setSharedWith($sharedWith); + + $recipient = $this->getMock('\OCP\IUser'); + $sharedWith->method('inGroup')->with($recipient)->willReturn(false); + + $this->manager->moveShare($share, $recipient); + } + + public function testMoveShareGroup() { + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP); + + $sharedWith = $this->getMock('\OCP\IGroup'); + $share->setSharedWith($sharedWith); + + $recipient = $this->getMock('\OCP\IUser'); + $sharedWith->method('inGroup')->with($recipient)->willReturn(true); + + $this->defaultProvider->method('move')->with($share, $recipient)->will($this->returnArgument(0)); + + $this->manager->moveShare($share, $recipient); + } } class DummyPassword { |