diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php index b30931c615e65..349181a540cab 100644 --- a/lib/private/Notification/Notification.php +++ b/lib/private/Notification/Notification.php @@ -56,6 +56,11 @@ public function __construct( $this->dateTime->setTimestamp(0); } + public function __clone() { + $this->actions = array_map(static fn (IAction $action): IAction => clone $action, $this->actions); + $this->actionsParsed = array_map(static fn (IAction $action): IAction => clone $action, $this->actionsParsed); + } + /** * {@inheritDoc} */ diff --git a/tests/lib/Notification/NotificationTest.php b/tests/lib/Notification/NotificationTest.php index d684f3876f8a0..1e67a239c259c 100644 --- a/tests/lib/Notification/NotificationTest.php +++ b/tests/lib/Notification/NotificationTest.php @@ -9,6 +9,7 @@ namespace Test\Notification; +use OC\Notification\Action; use OC\Notification\Notification; use OCP\Notification\IAction; use OCP\Notification\INotification; @@ -649,4 +650,26 @@ public function testIsValidCommon($app, $user, $timestamp, $objectType, $objectI $this->assertEquals($expected, $this->invokePrivate($notification, 'isValidCommon')); } + + public function testCloneDoesNotShareActions(): void { + $action = new Action(); + $action->setLabel('accept') + ->setLink('https://example.tld/accept', 'POST'); + $this->notification->addAction($action); + + $parsedAction = new Action(); + $parsedAction->setLabel('decline') + ->setParsedLabel('Decline') + ->setLink('https://example.tld/decline', 'POST'); + $this->notification->addParsedAction($parsedAction); + + $clone = clone $this->notification; + $clone->getActions()[0]->setParsedLabel('Accept'); + $clone->getParsedActions()[0]->setParsedLabel('Ablehnen'); + + $this->assertSame('', $action->getParsedLabel()); + $this->assertSame('Decline', $parsedAction->getParsedLabel()); + $this->assertSame('Accept', $clone->getActions()[0]->getParsedLabel()); + $this->assertSame('Ablehnen', $clone->getParsedActions()[0]->getParsedLabel()); + } }