diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2017-01-10 13:06:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 13:06:20 +0100 |
commit | a5bf14ada3b7edab724fac30ea89996f1a10f157 (patch) | |
tree | 56196a13adb29196136d15dd3e848d8d84562fcd /tests | |
parent | 3fa715c2ab0c48aa141a5b2813b3fdcff88aeb8e (diff) | |
parent | 0c11209d33178a93cb8229573c445b49eaf2326f (diff) | |
download | nextcloud-server-a5bf14ada3b7edab724fac30ea89996f1a10f157.tar.gz nextcloud-server-a5bf14ada3b7edab724fac30ea89996f1a10f157.zip |
Merge pull request #2955 from nextcloud/make-share-by-mail-work-without-linkshares
share by mail should continue to work, even if public links are disabled
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 00009a73b0e..7b01a8f9e70 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -1768,6 +1768,116 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals('hashed', $share->getPassword()); } + public function testCreateShareMail() { + $manager = $this->createManagerMock() + ->setMethods([ + 'canShare', + 'generalCreateChecks', + 'linkCreateChecks', + 'pathCreateChecks', + 'validateExpirationDate', + 'verifyPassword', + 'setLinkParent', + ]) + ->getMock(); + + $shareOwner = $this->createMock(IUser::class); + $shareOwner->method('getUID')->willReturn('shareOwner'); + + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); + $path->method('getOwner')->willReturn($shareOwner); + $path->method('getName')->willReturn('target'); + $path->method('getId')->willReturn(1); + $path->method('getStorage')->willReturn($storage); + + $share = $this->manager->newShare(); + $share->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) + ->setNode($path) + ->setSharedBy('sharedBy') + ->setPermissions(\OCP\Constants::PERMISSION_ALL); + + $manager->expects($this->once()) + ->method('canShare') + ->with($share) + ->willReturn(true); + $manager->expects($this->once()) + ->method('generalCreateChecks') + ->with($share);; + $manager->expects($this->never()) + ->method('linkCreateChecks'); + $manager->expects($this->once()) + ->method('pathCreateChecks') + ->with($path); + $manager->expects($this->never()) + ->method('validateExpirationDate'); + $manager->expects($this->never()) + ->method('verifyPassword'); + $manager->expects($this->never()) + ->method('setLinkParent'); + + $this->secureRandom->method('getMediumStrengthGenerator') + ->will($this->returnSelf()); + $this->secureRandom->method('generate') + ->willReturn('token'); + + $this->defaultProvider + ->expects($this->once()) + ->method('create') + ->with($share) + ->will($this->returnCallback(function(Share $share) { + return $share->setId(42); + })); + + $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'pre_shared', $hookListner, 'pre'); + \OCP\Util::connectHook('OCP\Share', 'post_shared', $hookListner, 'post'); + + $hookListnerExpectsPre = [ + 'itemType' => 'file', + 'itemSource' => 1, + 'shareType' => \OCP\Share::SHARE_TYPE_EMAIL, + 'uidOwner' => 'sharedBy', + 'permissions' => 31, + 'fileSource' => 1, + 'expiration' => null, + 'token' => 'token', + 'run' => true, + 'error' => '', + 'itemTarget' => '/target', + 'shareWith' => null, + ]; + + $hookListnerExpectsPost = [ + 'itemType' => 'file', + 'itemSource' => 1, + 'shareType' => \OCP\Share::SHARE_TYPE_EMAIL, + 'uidOwner' => 'sharedBy', + 'permissions' => 31, + 'fileSource' => 1, + 'expiration' => null, + 'token' => 'token', + 'id' => 42, + 'itemTarget' => '/target', + 'fileTarget' => '/target', + 'shareWith' => null, + ]; + + $hookListner->expects($this->once()) + ->method('pre') + ->with($this->equalTo($hookListnerExpectsPre)); + $hookListner->expects($this->once()) + ->method('post') + ->with($this->equalTo($hookListnerExpectsPost)); + + /** @var IShare $share */ + $share = $manager->createShare($share); + + $this->assertSame('shareOwner', $share->getShareOwner()); + $this->assertEquals('/target', $share->getTarget()); + $this->assertEquals('token', $share->getToken()); + } + /** * @expectedException Exception * @expectedExceptionMessage I won't let you share |