Merge pull request #20539 from owncloud/notification-api-adjustment
Notification api update
This commit is contained in:
commit
705d208a8a
|
@ -39,6 +39,9 @@ class Action implements IAction {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $icon;
|
protected $icon;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
protected $primary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -94,6 +97,27 @@ class Action implements IAction {
|
||||||
return $this->labelParsed;
|
return $this->labelParsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $primary bool
|
||||||
|
* @throws \InvalidArgumentException if $primary is invalid
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
public function setPrimary($primary) {
|
||||||
|
if (!is_bool($primary)) {
|
||||||
|
throw new \InvalidArgumentException('The given primary option is invalid');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->primary = $primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
public function isPrimary() {
|
||||||
|
return $this->primary;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $link
|
* @param string $link
|
||||||
* @param string $requestType
|
* @param string $requestType
|
||||||
|
@ -129,28 +153,6 @@ class Action implements IAction {
|
||||||
return $this->requestType;
|
return $this->requestType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $icon
|
|
||||||
* @return $this
|
|
||||||
* @throws \InvalidArgumentException if the icon is invalid
|
|
||||||
* @since 8.2.0
|
|
||||||
*/
|
|
||||||
public function setIcon($icon) {
|
|
||||||
if (!is_string($icon) || $icon === '' || isset($icon[64])) {
|
|
||||||
throw new \InvalidArgumentException('The given icon is invalid');
|
|
||||||
}
|
|
||||||
$this->icon = $icon;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @since 8.2.0
|
|
||||||
*/
|
|
||||||
public function getIcon() {
|
|
||||||
return $this->icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -60,6 +60,19 @@ interface IAction {
|
||||||
*/
|
*/
|
||||||
public function getParsedLabel();
|
public function getParsedLabel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $primary bool
|
||||||
|
* @throws \InvalidArgumentException if $primary is invalid
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
public function setPrimary($primary);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
public function isPrimary();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $link
|
* @param string $link
|
||||||
* @param string $requestType
|
* @param string $requestType
|
||||||
|
@ -81,20 +94,6 @@ interface IAction {
|
||||||
*/
|
*/
|
||||||
public function getRequestType();
|
public function getRequestType();
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $icon
|
|
||||||
* @return $this
|
|
||||||
* @throws \InvalidArgumentException if the icon is invalid
|
|
||||||
* @since 8.2.0
|
|
||||||
*/
|
|
||||||
public function setIcon($icon);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @since 8.2.0
|
|
||||||
*/
|
|
||||||
public function getIcon();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
* @since 8.2.0
|
* @since 8.2.0
|
||||||
|
|
|
@ -179,20 +179,6 @@ interface INotification {
|
||||||
*/
|
*/
|
||||||
public function getLink();
|
public function getLink();
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $icon
|
|
||||||
* @return $this
|
|
||||||
* @throws \InvalidArgumentException if the icon are invalid
|
|
||||||
* @since 8.2.0
|
|
||||||
*/
|
|
||||||
public function setIcon($icon);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @since 8.2.0
|
|
||||||
*/
|
|
||||||
public function getIcon();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return IAction
|
* @return IAction
|
||||||
* @since 8.2.0
|
* @since 8.2.0
|
||||||
|
|
|
@ -68,6 +68,12 @@ class Notification implements INotification {
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $actionsParsed;
|
protected $actionsParsed;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
protected $hasPrimaryAction;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
protected $hasPrimaryParsedAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -329,28 +335,6 @@ class Notification implements INotification {
|
||||||
return $this->link;
|
return $this->link;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $icon
|
|
||||||
* @return $this
|
|
||||||
* @throws \InvalidArgumentException if the icon are invalid
|
|
||||||
* @since 8.2.0
|
|
||||||
*/
|
|
||||||
public function setIcon($icon) {
|
|
||||||
if (!is_string($icon) || $icon === '' || isset($icon[64])) {
|
|
||||||
throw new \InvalidArgumentException('The given icon is invalid');
|
|
||||||
}
|
|
||||||
$this->icon = $icon;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @since 8.2.0
|
|
||||||
*/
|
|
||||||
public function getIcon() {
|
|
||||||
return $this->icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return IAction
|
* @return IAction
|
||||||
* @since 8.2.0
|
* @since 8.2.0
|
||||||
|
@ -369,6 +353,15 @@ class Notification implements INotification {
|
||||||
if (!$action->isValid()) {
|
if (!$action->isValid()) {
|
||||||
throw new \InvalidArgumentException('The given action is invalid');
|
throw new \InvalidArgumentException('The given action is invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($action->isPrimary()) {
|
||||||
|
if ($this->hasPrimaryAction) {
|
||||||
|
throw new \InvalidArgumentException('The notification already has a primary action');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->hasPrimaryAction = true;
|
||||||
|
}
|
||||||
|
|
||||||
$this->actions[] = $action;
|
$this->actions[] = $action;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -391,6 +384,15 @@ class Notification implements INotification {
|
||||||
if (!$action->isValidParsed()) {
|
if (!$action->isValidParsed()) {
|
||||||
throw new \InvalidArgumentException('The given parsed action is invalid');
|
throw new \InvalidArgumentException('The given parsed action is invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($action->isPrimary()) {
|
||||||
|
if ($this->hasPrimaryParsedAction) {
|
||||||
|
throw new \InvalidArgumentException('The notification already has a primary action');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->hasPrimaryParsedAction = true;
|
||||||
|
}
|
||||||
|
|
||||||
$this->actionsParsed[] = $action;
|
$this->actionsParsed[] = $action;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,47 +171,6 @@ class ActionTest extends TestCase {
|
||||||
$this->action->setLink($link, $type);
|
$this->action->setLink($link, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataSetIcon() {
|
|
||||||
return [
|
|
||||||
['test1'],
|
|
||||||
[str_repeat('a', 1)],
|
|
||||||
[str_repeat('a', 64)],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataSetIcon
|
|
||||||
* @param string $icon
|
|
||||||
*/
|
|
||||||
public function testSetIcon($icon) {
|
|
||||||
$this->assertSame('', $this->action->getIcon());
|
|
||||||
$this->action->setIcon($icon);
|
|
||||||
$this->assertSame($icon, $this->action->getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dataSetIconInvalid() {
|
|
||||||
return [
|
|
||||||
[true],
|
|
||||||
[false],
|
|
||||||
[0],
|
|
||||||
[1],
|
|
||||||
[''],
|
|
||||||
[str_repeat('a', 65)],
|
|
||||||
[[]],
|
|
||||||
[[str_repeat('a', 65)]],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataSetIconInvalid
|
|
||||||
* @param string $icon
|
|
||||||
*
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function testSetIconInvalid($icon) {
|
|
||||||
$this->action->setIcon($icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsValid() {
|
public function testIsValid() {
|
||||||
$this->assertFalse($this->action->isValid());
|
$this->assertFalse($this->action->isValid());
|
||||||
$this->assertFalse($this->action->isValidParsed());
|
$this->assertFalse($this->action->isValidParsed());
|
||||||
|
|
|
@ -371,34 +371,6 @@ class NotificationTest extends TestCase {
|
||||||
$this->notification->setLink($link);
|
$this->notification->setLink($link);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataSetIcon() {
|
|
||||||
return $this->dataValidString(64);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataSetIcon
|
|
||||||
* @param string $icon
|
|
||||||
*/
|
|
||||||
public function testSetIcon($icon) {
|
|
||||||
$this->assertSame('', $this->notification->getIcon());
|
|
||||||
$this->notification->setIcon($icon);
|
|
||||||
$this->assertSame($icon, $this->notification->getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dataSetIconInvalid() {
|
|
||||||
return $this->dataInvalidString(64);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataSetIconInvalid
|
|
||||||
* @param mixed $icon
|
|
||||||
*
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function testSetIconInvalid($icon) {
|
|
||||||
$this->notification->setIcon($icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCreateAction() {
|
public function testCreateAction() {
|
||||||
$action = $this->notification->createAction();
|
$action = $this->notification->createAction();
|
||||||
$this->assertInstanceOf('OC\Notification\IAction', $action);
|
$this->assertInstanceOf('OC\Notification\IAction', $action);
|
||||||
|
@ -438,6 +410,24 @@ class NotificationTest extends TestCase {
|
||||||
$this->notification->addAction($action);
|
$this->notification->addAction($action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAddActionSecondPrimary() {
|
||||||
|
/** @var \OC\Notification\IAction|\PHPUnit_Framework_MockObject_MockObject $action */
|
||||||
|
$action = $this->getMockBuilder('OC\Notification\IAction')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$action->expects($this->exactly(2))
|
||||||
|
->method('isValid')
|
||||||
|
->willReturn(true);
|
||||||
|
$action->expects($this->exactly(2))
|
||||||
|
->method('isPrimary')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->notification->addAction($action);
|
||||||
|
|
||||||
|
$this->setExpectedException('\InvalidArgumentException');
|
||||||
|
$this->notification->addAction($action);
|
||||||
|
}
|
||||||
|
|
||||||
public function testAddParsedAction() {
|
public function testAddParsedAction() {
|
||||||
/** @var \OC\Notification\IAction|\PHPUnit_Framework_MockObject_MockObject $action */
|
/** @var \OC\Notification\IAction|\PHPUnit_Framework_MockObject_MockObject $action */
|
||||||
$action = $this->getMockBuilder('OC\Notification\IAction')
|
$action = $this->getMockBuilder('OC\Notification\IAction')
|
||||||
|
@ -472,6 +462,24 @@ class NotificationTest extends TestCase {
|
||||||
$this->notification->addParsedAction($action);
|
$this->notification->addParsedAction($action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAddActionSecondParsedPrimary() {
|
||||||
|
/** @var \OC\Notification\IAction|\PHPUnit_Framework_MockObject_MockObject $action */
|
||||||
|
$action = $this->getMockBuilder('OC\Notification\IAction')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$action->expects($this->exactly(2))
|
||||||
|
->method('isValidParsed')
|
||||||
|
->willReturn(true);
|
||||||
|
$action->expects($this->exactly(2))
|
||||||
|
->method('isPrimary')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->notification->addParsedAction($action);
|
||||||
|
|
||||||
|
$this->setExpectedException('\InvalidArgumentException');
|
||||||
|
$this->notification->addParsedAction($action);
|
||||||
|
}
|
||||||
|
|
||||||
public function dataIsValid() {
|
public function dataIsValid() {
|
||||||
return [
|
return [
|
||||||
[false, '', false],
|
[false, '', false],
|
||||||
|
|
Loading…
Reference in New Issue