aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-08-15 11:12:25 +0200
committerJoas Schilling <coding@schilljs.com>2016-08-15 11:13:54 +0200
commit3ed05f87695473e667a2e3bc9b2aa17c28d5342f (patch)
tree127aa2297612f30fb2bec2d14fd1035f7fa2e622
parentf3124b5052c0fd8647f816a91b6d250c2570279c (diff)
downloadnextcloud-server-3ed05f87695473e667a2e3bc9b2aa17c28d5342f.tar.gz
nextcloud-server-3ed05f87695473e667a2e3bc9b2aa17c28d5342f.zip
Make sure the primary action is always the first one
-rw-r--r--lib/private/Notification/Notification.php6
-rw-r--r--tests/lib/Notification/NotificationTest.php29
2 files changed, 34 insertions, 1 deletions
diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php
index 62a48f434fe..9b5877a3058 100644
--- a/lib/private/Notification/Notification.php
+++ b/lib/private/Notification/Notification.php
@@ -397,9 +397,13 @@ class Notification implements INotification {
}
$this->hasPrimaryParsedAction = true;
+
+ // Make sure the primary action is always the first one
+ array_unshift($this->actionsParsed, $action);
+ } else {
+ $this->actionsParsed[] = $action;
}
- $this->actionsParsed[] = $action;
return $this;
}
diff --git a/tests/lib/Notification/NotificationTest.php b/tests/lib/Notification/NotificationTest.php
index c6ededf0142..93d48dfd604 100644
--- a/tests/lib/Notification/NotificationTest.php
+++ b/tests/lib/Notification/NotificationTest.php
@@ -495,6 +495,35 @@ class NotificationTest extends TestCase {
$this->notification->addParsedAction($action);
}
+ public function testAddActionParsedPrimaryEnd() {
+ /** @var \OCP\Notification\IAction|\PHPUnit_Framework_MockObject_MockObject $action */
+ $action1 = $this->getMockBuilder('OCP\Notification\IAction')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $action1->expects($this->exactly(2))
+ ->method('isValidParsed')
+ ->willReturn(true);
+ $action1->expects($this->exactly(2))
+ ->method('isPrimary')
+ ->willReturn(false);
+ /** @var \OCP\Notification\IAction|\PHPUnit_Framework_MockObject_MockObject $action */
+ $action2 = $this->getMockBuilder('OCP\Notification\IAction')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $action2->expects($this->once())
+ ->method('isValidParsed')
+ ->willReturn(true);
+ $action2->expects($this->once())
+ ->method('isPrimary')
+ ->willReturn(true);
+
+ $this->assertSame($this->notification, $this->notification->addParsedAction($action1));
+ $this->assertSame($this->notification, $this->notification->addParsedAction($action2));
+ $this->assertSame($this->notification, $this->notification->addParsedAction($action1));
+
+ $this->assertEquals([$action2, $action1, $action1], $this->notification->getParsedActions());
+ }
+
public function dataIsValid() {
return [
[false, '', false],