diff --git a/lib/private/notification/action.php b/lib/private/notification/action.php index 958b085b38..8eade69702 100644 --- a/lib/private/notification/action.php +++ b/lib/private/notification/action.php @@ -50,7 +50,7 @@ class Action implements IAction { $this->labelParsed = ''; $this->link = ''; $this->requestType = ''; - $this->icon = ''; + $this->primary = false; } /** @@ -99,6 +99,7 @@ class Action implements IAction { /** * @param $primary bool + * @return $this * @throws \InvalidArgumentException if $primary is invalid * @since 9.0.0 */ @@ -108,6 +109,7 @@ class Action implements IAction { } $this->primary = $primary; + return $this; } /** diff --git a/lib/private/notification/iaction.php b/lib/private/notification/iaction.php index 4aed2e9251..f7366dd438 100644 --- a/lib/private/notification/iaction.php +++ b/lib/private/notification/iaction.php @@ -62,6 +62,7 @@ interface IAction { /** * @param $primary bool + * @return $this * @throws \InvalidArgumentException if $primary is invalid * @since 9.0.0 */ diff --git a/tests/lib/notification/actiontest.php b/tests/lib/notification/actiontest.php index a6157d6c56..0044df82cd 100644 --- a/tests/lib/notification/actiontest.php +++ b/tests/lib/notification/actiontest.php @@ -49,7 +49,7 @@ class ActionTest extends TestCase { */ public function testSetLabel($label) { $this->assertSame('', $this->action->getLabel()); - $this->action->setLabel($label); + $this->assertSame($this->action, $this->action->setLabel($label)); $this->assertSame($label, $this->action->getLabel()); } @@ -68,7 +68,7 @@ class ActionTest extends TestCase { /** * @dataProvider dataSetLabelInvalid - * @param string $label + * @param mixed $label * * @expectedException \InvalidArgumentException */ @@ -90,7 +90,7 @@ class ActionTest extends TestCase { */ public function testSetParsedLabel($label) { $this->assertSame('', $this->action->getParsedLabel()); - $this->action->setParsedLabel($label); + $this->assertSame($this->action, $this->action->setParsedLabel($label)); $this->assertSame($label, $this->action->getParsedLabel()); } @@ -108,7 +108,7 @@ class ActionTest extends TestCase { /** * @dataProvider dataSetParsedLabelInvalid - * @param string $label + * @param mixed $label * * @expectedException \InvalidArgumentException */ @@ -132,7 +132,7 @@ class ActionTest extends TestCase { */ public function testSetLink($link, $type) { $this->assertSame('', $this->action->getLink()); - $this->action->setLink($link, $type); + $this->assertSame($this->action, $this->action->setLink($link, $type)); $this->assertSame($link, $this->action->getLink()); $this->assertSame($type, $this->action->getRequestType()); } @@ -162,8 +162,8 @@ class ActionTest extends TestCase { /** * @dataProvider dataSetLinkInvalid - * @param string $link - * @param string $type + * @param mixed $link + * @param mixed $type * * @expectedException \InvalidArgumentException */ @@ -171,6 +171,44 @@ class ActionTest extends TestCase { $this->action->setLink($link, $type); } + public function dataSetPrimary() { + return [ + [true], + [false], + ]; + } + + /** + * @dataProvider dataSetPrimary + * @param bool $primary + */ + public function testSetPrimary($primary) { + $this->assertSame(false, $this->action->isPrimary()); + $this->assertSame($this->action, $this->action->setPrimary($primary)); + $this->assertSame($primary, $this->action->isPrimary()); + } + + public function dataSetPrimaryInvalid() { + return [ + [0], + [1], + [''], + [str_repeat('a', 257)], + [[]], + [[str_repeat('a', 257)]], + ]; + } + + /** + * @dataProvider dataSetPrimaryInvalid + * @param mixed $primary + * + * @expectedException \InvalidArgumentException + */ + public function testSetPrimaryInvalid($primary) { + $this->action->setPrimary($primary); + } + public function testIsValid() { $this->assertFalse($this->action->isValid()); $this->assertFalse($this->action->isValidParsed()); diff --git a/tests/lib/notification/notificationtest.php b/tests/lib/notification/notificationtest.php index 8be49ebdc1..662dc5a617 100644 --- a/tests/lib/notification/notificationtest.php +++ b/tests/lib/notification/notificationtest.php @@ -93,7 +93,7 @@ class NotificationTest extends TestCase { */ public function testSetApp($app) { $this->assertSame('', $this->notification->getApp()); - $this->notification->setApp($app); + $this->assertSame($this->notification, $this->notification->setApp($app)); $this->assertSame($app, $this->notification->getApp()); } @@ -121,7 +121,7 @@ class NotificationTest extends TestCase { */ public function testSetUser($user) { $this->assertSame('', $this->notification->getUser()); - $this->notification->setUser($user); + $this->assertSame($this->notification, $this->notification->setUser($user)); $this->assertSame($user, $this->notification->getUser()); } @@ -149,7 +149,7 @@ class NotificationTest extends TestCase { */ public function testSetTimestamp($timestamp) { $this->assertSame(0, $this->notification->getTimestamp()); - $this->notification->setTimestamp($timestamp); + $this->assertSame($this->notification, $this->notification->setTimestamp($timestamp)); $this->assertSame($timestamp, $this->notification->getTimestamp()); } @@ -182,7 +182,7 @@ class NotificationTest extends TestCase { public function testSetObject($type, $id) { $this->assertSame('', $this->notification->getObjectType()); $this->assertSame(0, $this->notification->getObjectId()); - $this->notification->setObject($type, $id); + $this->assertSame($this->notification, $this->notification->setObject($type, $id)); $this->assertSame($type, $this->notification->getObjectType()); $this->assertSame($id, $this->notification->getObjectId()); } @@ -233,7 +233,7 @@ class NotificationTest extends TestCase { public function testSetSubject($subject, $parameters) { $this->assertSame('', $this->notification->getSubject()); $this->assertSame([], $this->notification->getSubjectParameters()); - $this->notification->setSubject($subject, $parameters); + $this->assertSame($this->notification, $this->notification->setSubject($subject, $parameters)); $this->assertSame($subject, $this->notification->getSubject()); $this->assertSame($parameters, $this->notification->getSubjectParameters()); } @@ -262,7 +262,7 @@ class NotificationTest extends TestCase { */ public function testSetParsedSubject($subject) { $this->assertSame('', $this->notification->getParsedSubject()); - $this->notification->setParsedSubject($subject); + $this->assertSame($this->notification, $this->notification->setParsedSubject($subject)); $this->assertSame($subject, $this->notification->getParsedSubject()); } @@ -296,7 +296,7 @@ class NotificationTest extends TestCase { public function testSetMessage($message, $parameters) { $this->assertSame('', $this->notification->getMessage()); $this->assertSame([], $this->notification->getMessageParameters()); - $this->notification->setMessage($message, $parameters); + $this->assertSame($this->notification, $this->notification->setMessage($message, $parameters)); $this->assertSame($message, $this->notification->getMessage()); $this->assertSame($parameters, $this->notification->getMessageParameters()); } @@ -325,7 +325,7 @@ class NotificationTest extends TestCase { */ public function testSetParsedMessage($message) { $this->assertSame('', $this->notification->getParsedMessage()); - $this->notification->setParsedMessage($message); + $this->assertSame($this->notification, $this->notification->setParsedMessage($message)); $this->assertSame($message, $this->notification->getParsedMessage()); } @@ -353,7 +353,7 @@ class NotificationTest extends TestCase { */ public function testSetLink($link) { $this->assertSame('', $this->notification->getLink()); - $this->notification->setLink($link); + $this->assertSame($this->notification, $this->notification->setLink($link)); $this->assertSame($link, $this->notification->getLink()); } @@ -387,7 +387,7 @@ class NotificationTest extends TestCase { $action->expects($this->never()) ->method('isValidParsed'); - $this->notification->addAction($action); + $this->assertSame($this->notification, $this->notification->addAction($action)); $this->assertEquals([$action], $this->notification->getActions()); $this->assertEquals([], $this->notification->getParsedActions()); @@ -422,7 +422,7 @@ class NotificationTest extends TestCase { ->method('isPrimary') ->willReturn(true); - $this->notification->addAction($action); + $this->assertSame($this->notification, $this->notification->addAction($action)); $this->setExpectedException('\InvalidArgumentException'); $this->notification->addAction($action); @@ -439,7 +439,7 @@ class NotificationTest extends TestCase { $action->expects($this->never()) ->method('isValid'); - $this->notification->addParsedAction($action); + $this->assertSame($this->notification, $this->notification->addParsedAction($action)); $this->assertEquals([$action], $this->notification->getParsedActions()); $this->assertEquals([], $this->notification->getActions()); @@ -474,7 +474,7 @@ class NotificationTest extends TestCase { ->method('isPrimary') ->willReturn(true); - $this->notification->addParsedAction($action); + $this->assertSame($this->notification, $this->notification->addParsedAction($action)); $this->setExpectedException('\InvalidArgumentException'); $this->notification->addParsedAction($action);