Skip to content

Commit

Permalink
Merge pull request #1660 from nextcloud/add-notification-icon-to-api
Browse files Browse the repository at this point in the history
Add an icon to the notification API
  • Loading branch information
ChristophWurst authored Oct 10, 2016
2 parents e5fd9c1 + c77933c commit a0cb809
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
32 changes: 27 additions & 5 deletions lib/private/Notification/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function getSubjectParameters() {
/**
* @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) {
Expand Down Expand Up @@ -300,7 +300,7 @@ public function getMessageParameters() {
/**
* @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) {
Expand All @@ -322,7 +322,7 @@ public function getParsedMessage() {
/**
* @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) {
Expand All @@ -341,6 +341,28 @@ public function getLink() {
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
Expand All @@ -352,7 +374,7 @@ public function createAction() {
/**
* @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) {
Expand Down Expand Up @@ -383,7 +405,7 @@ public function getActions() {
/**
* @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) {
Expand Down
28 changes: 21 additions & 7 deletions lib/public/Notification/INotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -46,7 +46,7 @@ public function getApp();
/**
* @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);
Expand Down Expand Up @@ -116,7 +116,7 @@ public function getSubjectParameters();
/**
* @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);
Expand Down Expand Up @@ -151,7 +151,7 @@ public function getMessageParameters();
/**
* @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);
Expand All @@ -165,7 +165,7 @@ public function getParsedMessage();
/**
* @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);
Expand All @@ -176,6 +176,20 @@ public function setLink($link);
*/
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
Expand All @@ -185,7 +199,7 @@ public function createAction();
/**
* @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);
Expand All @@ -199,7 +213,7 @@ public function getActions();
/**
* @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);
Expand Down
28 changes: 28 additions & 0 deletions tests/lib/Notification/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,34 @@ public function testSetLinkInvalid($link) {
$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);
Expand Down

0 comments on commit a0cb809

Please sign in to comment.