Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/private/Notification/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,13 @@ public function addParsedAction(IAction $action) {
}

$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;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/lib/Notification/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,35 @@ public function testAddActionSecondParsedPrimary() {
$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],
Expand Down