From c77933ca22bb7614f546bacbb62f22e2fa3074f5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Oct 2016 17:00:24 +0200 Subject: [PATCH] Add an icon to the notification API Signed-off-by: Joas Schilling --- lib/private/Notification/Notification.php | 32 +++++++++++++++++---- lib/public/Notification/INotification.php | 28 +++++++++++++----- tests/lib/Notification/NotificationTest.php | 28 ++++++++++++++++++ 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php index 9b5877a305..7bf4b9a74c 100644 --- a/lib/private/Notification/Notification.php +++ b/lib/private/Notification/Notification.php @@ -242,7 +242,7 @@ class Notification implements INotification { /** * @param string $subject * @return $this - * @throws \InvalidArgumentException if the subject are invalid + * @throws \InvalidArgumentException if the subject is invalid * @since 8.2.0 */ public function setParsedSubject($subject) { @@ -300,7 +300,7 @@ class Notification implements INotification { /** * @param string $message * @return $this - * @throws \InvalidArgumentException if the message are invalid + * @throws \InvalidArgumentException if the message is invalid * @since 8.2.0 */ public function setParsedMessage($message) { @@ -322,7 +322,7 @@ class Notification implements INotification { /** * @param string $link * @return $this - * @throws \InvalidArgumentException if the link are invalid + * @throws \InvalidArgumentException if the link is invalid * @since 8.2.0 */ public function setLink($link) { @@ -341,6 +341,28 @@ class Notification implements INotification { return $this->link; } + /** + * @param string $icon + * @return $this + * @throws \InvalidArgumentException if the icon is invalid + * @since 9.2.0 + */ + public function setIcon($icon) { + if (!is_string($icon) || $icon === '' || isset($icon[4000])) { + throw new \InvalidArgumentException('The given icon is invalid'); + } + $this->icon = $icon; + return $this; + } + + /** + * @return string + * @since 9.2.0 + */ + public function getIcon() { + return $this->icon; + } + /** * @return IAction * @since 8.2.0 @@ -352,7 +374,7 @@ class Notification implements INotification { /** * @param IAction $action * @return $this - * @throws \InvalidArgumentException if the action are invalid + * @throws \InvalidArgumentException if the action is invalid * @since 8.2.0 */ public function addAction(IAction $action) { @@ -383,7 +405,7 @@ class Notification implements INotification { /** * @param IAction $action * @return $this - * @throws \InvalidArgumentException if the action are invalid + * @throws \InvalidArgumentException if the action is invalid * @since 8.2.0 */ public function addParsedAction(IAction $action) { diff --git a/lib/public/Notification/INotification.php b/lib/public/Notification/INotification.php index 492e30dfaf..fd16876a66 100644 --- a/lib/public/Notification/INotification.php +++ b/lib/public/Notification/INotification.php @@ -32,7 +32,7 @@ interface INotification { /** * @param string $app * @return $this - * @throws \InvalidArgumentException if the app id are invalid + * @throws \InvalidArgumentException if the app id is invalid * @since 9.0.0 */ public function setApp($app); @@ -46,7 +46,7 @@ interface INotification { /** * @param string $user * @return $this - * @throws \InvalidArgumentException if the user id are invalid + * @throws \InvalidArgumentException if the user id is invalid * @since 9.0.0 */ public function setUser($user); @@ -116,7 +116,7 @@ interface INotification { /** * @param string $subject * @return $this - * @throws \InvalidArgumentException if the subject are invalid + * @throws \InvalidArgumentException if the subject is invalid * @since 9.0.0 */ public function setParsedSubject($subject); @@ -151,7 +151,7 @@ interface INotification { /** * @param string $message * @return $this - * @throws \InvalidArgumentException if the message are invalid + * @throws \InvalidArgumentException if the message is invalid * @since 9.0.0 */ public function setParsedMessage($message); @@ -165,7 +165,7 @@ interface INotification { /** * @param string $link * @return $this - * @throws \InvalidArgumentException if the link are invalid + * @throws \InvalidArgumentException if the link is invalid * @since 9.0.0 */ public function setLink($link); @@ -176,6 +176,20 @@ interface INotification { */ public function getLink(); + /** + * @param string $icon + * @return $this + * @throws \InvalidArgumentException if the icon is invalid + * @since 9.2.0 + */ + public function setIcon($icon); + + /** + * @return string + * @since 9.2.0 + */ + public function getIcon(); + /** * @return IAction * @since 9.0.0 @@ -185,7 +199,7 @@ interface INotification { /** * @param IAction $action * @return $this - * @throws \InvalidArgumentException if the action are invalid + * @throws \InvalidArgumentException if the action is invalid * @since 9.0.0 */ public function addAction(IAction $action); @@ -199,7 +213,7 @@ interface INotification { /** * @param IAction $action * @return $this - * @throws \InvalidArgumentException if the action are invalid + * @throws \InvalidArgumentException if the action is invalid * @since 9.0.0 */ public function addParsedAction(IAction $action); diff --git a/tests/lib/Notification/NotificationTest.php b/tests/lib/Notification/NotificationTest.php index 93d48dfd60..77d9e989cf 100644 --- a/tests/lib/Notification/NotificationTest.php +++ b/tests/lib/Notification/NotificationTest.php @@ -386,6 +386,34 @@ class NotificationTest extends TestCase { $this->notification->setLink($link); } + public function dataSetIcon() { + return $this->dataValidString(4000); + } + + /** + * @dataProvider dataSetIcon + * @param string $icon + */ + public function testSetIcon($icon) { + $this->assertSame('', $this->notification->getIcon()); + $this->assertSame($this->notification, $this->notification->setIcon($icon)); + $this->assertSame($icon, $this->notification->getIcon()); + } + + public function dataSetIconInvalid() { + return $this->dataInvalidString(4000); + } + + /** + * @dataProvider dataSetIconInvalid + * @param mixed $icon + * + * @expectedException \InvalidArgumentException + */ + public function testSetIconInvalid($icon) { + $this->notification->setIcon($icon); + } + public function testCreateAction() { $action = $this->notification->createAction(); $this->assertInstanceOf('OCP\Notification\IAction', $action);