summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPauli Järvinen <pauli.jarvinen@gmail.com>2017-07-16 17:26:11 +0300
committerPauli Järvinen <pauli.jarvinen@gmail.com>2017-07-20 14:45:46 +0300
commit7c4a15f2155748a73718bb7482bbcd524ab0e6fc (patch)
tree9c236b80df77912f1860b61a298f3f5a99bc3774 /tests
parent8dce97a3e17a42ce734d5ca10899a08b96721f18 (diff)
downloadnextcloud-server-7c4a15f2155748a73718bb7482bbcd524ab0e6fc.tar.gz
nextcloud-server-7c4a15f2155748a73718bb7482bbcd524ab0e6fc.zip
Emit hook postUnshareFromSelf when the recipient of a share unshares it
- This kind of hook signal used to be emitted in the old Share library but it was missing from Share 2.0 Signed-off-by: Pauli Järvinen <pauli.jarvinen@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Share20/LegacyHooksTest.php52
-rw-r--r--tests/lib/Share20/ManagerTest.php34
2 files changed, 86 insertions, 0 deletions
diff --git a/tests/lib/Share20/LegacyHooksTest.php b/tests/lib/Share20/LegacyHooksTest.php
index 75a77306116..22d575d26ff 100644
--- a/tests/lib/Share20/LegacyHooksTest.php
+++ b/tests/lib/Share20/LegacyHooksTest.php
@@ -135,4 +135,56 @@ class LegacyHooksTest extends TestCase {
$event->setArgument('deletedShares', [$share]);
$this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
}
+
+ public function testPostUnshareFromSelf() {
+ $path = $this->createMock(File::class);
+ $path->method('getId')->willReturn(1);
+
+ $share = $this->manager->newShare();
+ $share->setId(42)
+ ->setProviderId('prov')
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith('awesomeUser')
+ ->setSharedBy('sharedBy')
+ ->setNode($path)
+ ->setTarget('myTarget');
+
+ $hookListner = $this->getMockBuilder('Dummy')->setMethods(['postFromSelf'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'post_unshareFromSelf', $hookListner, 'postFromSelf');
+
+ $hookListnerExpectsPostFromSelf = [
+ 'id' => 42,
+ 'itemType' => 'file',
+ 'itemSource' => 1,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'awesomeUser',
+ 'itemparent' => null,
+ 'uidOwner' => 'sharedBy',
+ 'fileSource' => 1,
+ 'fileTarget' => 'myTarget',
+ 'itemTarget' => 'myTarget',
+ 'unsharedItems' => [
+ [
+ 'id' => 42,
+ 'itemType' => 'file',
+ 'itemSource' => 1,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'awesomeUser',
+ 'itemparent' => null,
+ 'uidOwner' => 'sharedBy',
+ 'fileSource' => 1,
+ 'fileTarget' => 'myTarget',
+ 'itemTarget' => 'myTarget',
+ ],
+ ],
+ ];
+
+ $hookListner
+ ->expects($this->exactly(1))
+ ->method('postFromSelf')
+ ->with($hookListnerExpectsPostFromSelf);
+
+ $event = new GenericEvent($share);
+ $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
+ }
}
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 1cc165106d7..a764350c406 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -332,6 +332,40 @@ class ManagerTest extends \Test\TestCase {
$manager->deleteShare($share1);
}
+ public function testDeleteFromSelf() {
+ $manager = $this->createManagerMock()
+ ->setMethods(['getShareById'])
+ ->getMock();
+
+ $recipientId = 'unshareFrom';
+ $share = $this->manager->newShare();
+ $share->setId(42)
+ ->setProviderId('prov')
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith('sharedWith')
+ ->setSharedBy('sharedBy')
+ ->setShareOwner('shareOwner')
+ ->setTarget('myTarget')
+ ->setNodeId(1)
+ ->setNodeType('file');
+
+ $this->defaultProvider
+ ->expects($this->once())
+ ->method('deleteFromSelf')
+ ->with($share, $recipientId);
+
+ $this->eventDispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with(
+ 'OCP\Share::postUnshareFromSelf',
+ $this->callBack(function(GenericEvent $e) use ($share) {
+ return $e->getSubject() === $share;
+ })
+ );
+
+ $manager->deleteFromSelf($share, $recipientId);
+ }
+
public function testDeleteChildren() {
$manager = $this->createManagerMock()
->setMethods(['deleteShare'])