public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() { $share = new \OC\Share20\Share(); $sharedWith = $this->getMock('\\OCP\\IGroup'); $share->setSharedWith($sharedWith); $path = $this->getMock('\\OCP\\Files\\Node'); $share->setPath($path); $share2 = new \OC\Share20\Share(); $sharedWith2 = $this->getMock('\\OCP\\IGroup'); $share2->setSharedWith($sharedWith2); $this->defaultProvider->method('getSharesByPath')->with($path)->willReturn([$share2]); $this->invokePrivate($this->manager, 'groupCreateChecks', [$share]); }
public function testDeleteNested() { $manager = $this->getMockBuilder('\\OC\\Share20\\Manager')->setConstructorArgs([$this->logger, $this->appConfig, $this->defaultProvider])->setMethods(['getShareById'])->getMock(); $sharedBy1 = $this->getMock('\\OCP\\IUser'); $sharedBy1->method('getUID')->willReturn('sharedBy1'); $sharedBy2 = $this->getMock('\\OCP\\IUser'); $sharedBy2->method('getUID')->willReturn('sharedBy2'); $sharedBy3 = $this->getMock('\\OCP\\IUser'); $sharedBy3->method('getUID')->willReturn('sharedBy3'); $sharedWith1 = $this->getMock('\\OCP\\IUser'); $sharedWith1->method('getUID')->willReturn('sharedWith1'); $sharedWith2 = $this->getMock('\\OCP\\IGroup'); $sharedWith2->method('getGID')->willReturn('sharedWith2'); $path = $this->getMock('\\OCP\\Files\\File'); $path->method('getId')->willReturn(1); $share1 = $this->getMock('\\OC\\Share20\\IShare'); $share1->method('getId')->willReturn(42); $share1->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $share1->method('getSharedWith')->willReturn($sharedWith1); $share1->method('getSharedBy')->willReturn($sharedBy1); $share1->method('getPath')->willReturn($path); $share1->method('getTarget')->willReturn('myTarget1'); $share2 = $this->getMock('\\OC\\Share20\\IShare'); $share2->method('getId')->willReturn(43); $share2->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); $share2->method('getSharedWith')->willReturn($sharedWith2); $share2->method('getSharedBy')->willReturn($sharedBy2); $share2->method('getPath')->willReturn($path); $share2->method('getTarget')->willReturn('myTarget2'); $share2->method('getParent')->willReturn(42); $share3 = $this->getMock('\\OC\\Share20\\IShare'); $share3->method('getId')->willReturn(44); $share3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share3->method('getSharedBy')->willReturn($sharedBy3); $share3->method('getPath')->willReturn($path); $share3->method('getTarget')->willReturn('myTarget3'); $share3->method('getParent')->willReturn(43); $manager->expects($this->once())->method('getShareById')->with(42)->willReturn($share1); $this->defaultProvider->method('getChildren')->will($this->returnValueMap([[$share1, [$share2]], [$share2, [$share3]], [$share3, []]])); $this->defaultProvider->method('delete')->withConsecutive($share3, $share2, $share1); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock(); \OCP\Util::connectHook('OCP\\Share', 'pre_unshare', $hookListner, 'pre'); \OCP\Util::connectHook('OCP\\Share', 'post_unshare', $hookListner, 'post'); $hookListnerExpectsPre = ['id' => 42, 'itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'sharedWith1', 'itemparent' => null, 'uidOwner' => 'sharedBy1', 'fileSource' => 1, 'fileTarget' => 'myTarget1']; $hookListnerExpectsPost = ['id' => 42, 'itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'sharedWith1', 'itemparent' => null, 'uidOwner' => 'sharedBy1', 'fileSource' => 1, 'fileTarget' => 'myTarget1', 'deletedShares' => [['id' => 44, 'itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_LINK, 'shareWith' => '', 'itemparent' => 43, 'uidOwner' => 'sharedBy3', 'fileSource' => 1, 'fileTarget' => 'myTarget3'], ['id' => 43, 'itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => 'sharedWith2', 'itemparent' => 42, 'uidOwner' => 'sharedBy2', 'fileSource' => 1, 'fileTarget' => 'myTarget2'], ['id' => 42, 'itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'sharedWith1', 'itemparent' => null, 'uidOwner' => 'sharedBy1', 'fileSource' => 1, 'fileTarget' => 'myTarget1']]]; $hookListner->expects($this->exactly(1))->method('pre')->with($hookListnerExpectsPre); $hookListner->expects($this->exactly(1))->method('post')->with($hookListnerExpectsPost); $manager->deleteShare($share1); }