aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Share20
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-07-27 22:25:26 +0200
committerJoas Schilling <coding@schilljs.com>2023-07-28 14:11:20 +0200
commit8ad94cbfda58c28dacaa391390033854abdfc8b3 (patch)
treeb6a7f2a3a986f2318335c4193e1de07564eb1d62 /tests/lib/Share20
parent44b810bfbd83fc6eb95a67430894dbd2cf6eb339 (diff)
downloadnextcloud-server-8ad94cbfda58c28dacaa391390033854abdfc8b3.tar.gz
nextcloud-server-8ad94cbfda58c28dacaa391390033854abdfc8b3.zip
feat!: Migrate unShare events to typed events
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests/lib/Share20')
-rw-r--r--tests/lib/Share20/LegacyHooksTest.php16
-rw-r--r--tests/lib/Share20/ManagerTest.php89
2 files changed, 64 insertions, 41 deletions
diff --git a/tests/lib/Share20/LegacyHooksTest.php b/tests/lib/Share20/LegacyHooksTest.php
index 596fba7bfad..c16480f6aba 100644
--- a/tests/lib/Share20/LegacyHooksTest.php
+++ b/tests/lib/Share20/LegacyHooksTest.php
@@ -32,7 +32,10 @@ use OCP\Files\Cache\ICacheEntry;
use OCP\Files\File;
use OCP\IServerContainer;
use OCP\Share\Events\BeforeShareCreatedEvent;
+use OCP\Share\Events\BeforeShareDeletedEvent;
use OCP\Share\Events\ShareCreatedEvent;
+use OCP\Share\Events\ShareDeletedEvent;
+use OCP\Share\Events\ShareDeletedFromSelfEvent;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
@@ -95,8 +98,8 @@ class LegacyHooksTest extends TestCase {
->method('pre')
->with($hookListnerExpectsPre);
- $event = new GenericEvent($share);
- $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event);
+ $event = new BeforeShareDeletedEvent($share);
+ $this->eventDispatcher->dispatchTyped($event);
}
public function testPostUnshare() {
@@ -149,9 +152,8 @@ class LegacyHooksTest extends TestCase {
->method('post')
->with($hookListnerExpectsPost);
- $event = new GenericEvent($share);
- $event->setArgument('deletedShares', [$share]);
- $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
+ $event = new ShareDeletedEvent($share);
+ $this->eventDispatcher->dispatchTyped($event);
}
public function testPostUnshareFromSelf() {
@@ -206,8 +208,8 @@ class LegacyHooksTest extends TestCase {
->method('postFromSelf')
->with($hookListnerExpectsPostFromSelf);
- $event = new GenericEvent($share);
- $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
+ $event = new ShareDeletedFromSelfEvent($share);
+ $this->eventDispatcher->dispatchTyped($event);
}
public function testPreShare() {
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 7a0c23ec2b4..c15d0456d48 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -52,7 +52,10 @@ use OCP\Security\Events\ValidatePasswordPolicyEvent;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use OCP\Share\Events\BeforeShareCreatedEvent;
+use OCP\Share\Events\BeforeShareDeletedEvent;
use OCP\Share\Events\ShareCreatedEvent;
+use OCP\Share\Events\ShareDeletedEvent;
+use OCP\Share\Events\ShareDeletedFromSelfEvent;
use OCP\Share\Exceptions\AlreadySharedException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
@@ -249,17 +252,16 @@ class ManagerTest extends \Test\TestCase {
->method('delete')
->with($share);
- $this->eventDispatcher->expects($this->exactly(2))
- ->method('dispatch')
+ $this->dispatcher->expects($this->exactly(2))
+ ->method('dispatchTyped')
->withConsecutive(
- ['OCP\Share::preUnshare',
- $this->callBack(function (GenericEvent $e) use ($share) {
- return $e->getSubject() === $share;
+ [
+ $this->callBack(function (BeforeShareDeletedEvent $e) use ($share) {
+ return $e->getShare() === $share;
})],
- ['OCP\Share::postUnshare',
- $this->callBack(function (GenericEvent $e) use ($share) {
- return $e->getSubject() === $share &&
- $e->getArgument('deletedShares') === [$share];
+ [
+ $this->callBack(function (ShareDeletedEvent $e) use ($share) {
+ return $e->getShare() === $share;
})]
);
@@ -293,17 +295,16 @@ class ManagerTest extends \Test\TestCase {
->method('delete')
->with($share);
- $this->eventDispatcher->expects($this->exactly(2))
- ->method('dispatch')
+ $this->dispatcher->expects($this->exactly(2))
+ ->method('dispatchTyped')
->withConsecutive(
- ['OCP\Share::preUnshare',
- $this->callBack(function (GenericEvent $e) use ($share) {
- return $e->getSubject() === $share;
+ [
+ $this->callBack(function (BeforeShareDeletedEvent $e) use ($share) {
+ return $e->getShare() === $share;
})],
- ['OCP\Share::postUnshare',
- $this->callBack(function (GenericEvent $e) use ($share) {
- return $e->getSubject() === $share &&
- $e->getArgument('deletedShares') === [$share];
+ [
+ $this->callBack(function (ShareDeletedEvent $e) use ($share) {
+ return $e->getShare() === $share;
})]
);
@@ -358,18 +359,39 @@ class ManagerTest extends \Test\TestCase {
->method('delete')
->withConsecutive([$share3], [$share2], [$share1]);
- $this->eventDispatcher->expects($this->exactly(2))
- ->method('dispatch')
+ $this->dispatcher->expects($this->exactly(6))
+ ->method('dispatchTyped')
->withConsecutive(
- ['OCP\Share::preUnshare',
- $this->callBack(function (GenericEvent $e) use ($share1) {
- return $e->getSubject() === $share1;
- })],
- ['OCP\Share::postUnshare',
- $this->callBack(function (GenericEvent $e) use ($share1, $share2, $share3) {
- return $e->getSubject() === $share1 &&
- $e->getArgument('deletedShares') === [$share3, $share2, $share1];
- })]
+ [
+ $this->callBack(function (BeforeShareDeletedEvent $e) use ($share1) {
+ return $e->getShare()->getId() === $share1->getId();
+ })
+ ],
+ [
+ $this->callBack(function (BeforeShareDeletedEvent $e) use ($share2) {
+ return $e->getShare()->getId() === $share2->getId();
+ })
+ ],
+ [
+ $this->callBack(function (BeforeShareDeletedEvent $e) use ($share3) {
+ return $e->getShare()->getId() === $share3->getId();
+ })
+ ],
+ [
+ $this->callBack(function (ShareDeletedEvent $e) use ($share3) {
+ return $e->getShare()->getId() === $share3->getId();
+ })
+ ],
+ [
+ $this->callBack(function (ShareDeletedEvent $e) use ($share2) {
+ return $e->getShare()->getId() === $share2->getId();
+ })
+ ],
+ [
+ $this->callBack(function (ShareDeletedEvent $e) use ($share1) {
+ return $e->getShare()->getId() === $share1->getId();
+ })
+ ],
);
$manager->deleteShare($share1);
@@ -397,12 +419,11 @@ class ManagerTest extends \Test\TestCase {
->method('deleteFromSelf')
->with($share, $recipientId);
- $this->eventDispatcher->expects($this->once())
- ->method('dispatch')
+ $this->dispatcher->expects($this->once())
+ ->method('dispatchTyped')
->with(
- 'OCP\Share::postUnshareFromSelf',
- $this->callBack(function (GenericEvent $e) use ($share) {
- return $e->getSubject() === $share;
+ $this->callBack(function (ShareDeletedFromSelfEvent $e) use ($share) {
+ return $e->getShare() === $share;
})
);