Merge pull request #20551 from owncloud/notification-fix-tests

Notification - Add tests for the "return $this" and fix it on the new method
This commit is contained in:
Thomas Müller 2015-11-18 09:12:27 +01:00
commit 8db9c49cda
4 changed files with 62 additions and 21 deletions

View File

@ -50,7 +50,7 @@ class Action implements IAction {
$this->labelParsed = ''; $this->labelParsed = '';
$this->link = ''; $this->link = '';
$this->requestType = ''; $this->requestType = '';
$this->icon = ''; $this->primary = false;
} }
/** /**
@ -99,6 +99,7 @@ class Action implements IAction {
/** /**
* @param $primary bool * @param $primary bool
* @return $this
* @throws \InvalidArgumentException if $primary is invalid * @throws \InvalidArgumentException if $primary is invalid
* @since 9.0.0 * @since 9.0.0
*/ */
@ -108,6 +109,7 @@ class Action implements IAction {
} }
$this->primary = $primary; $this->primary = $primary;
return $this;
} }
/** /**

View File

@ -62,6 +62,7 @@ interface IAction {
/** /**
* @param $primary bool * @param $primary bool
* @return $this
* @throws \InvalidArgumentException if $primary is invalid * @throws \InvalidArgumentException if $primary is invalid
* @since 9.0.0 * @since 9.0.0
*/ */

View File

@ -49,7 +49,7 @@ class ActionTest extends TestCase {
*/ */
public function testSetLabel($label) { public function testSetLabel($label) {
$this->assertSame('', $this->action->getLabel()); $this->assertSame('', $this->action->getLabel());
$this->action->setLabel($label); $this->assertSame($this->action, $this->action->setLabel($label));
$this->assertSame($label, $this->action->getLabel()); $this->assertSame($label, $this->action->getLabel());
} }
@ -68,7 +68,7 @@ class ActionTest extends TestCase {
/** /**
* @dataProvider dataSetLabelInvalid * @dataProvider dataSetLabelInvalid
* @param string $label * @param mixed $label
* *
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
@ -90,7 +90,7 @@ class ActionTest extends TestCase {
*/ */
public function testSetParsedLabel($label) { public function testSetParsedLabel($label) {
$this->assertSame('', $this->action->getParsedLabel()); $this->assertSame('', $this->action->getParsedLabel());
$this->action->setParsedLabel($label); $this->assertSame($this->action, $this->action->setParsedLabel($label));
$this->assertSame($label, $this->action->getParsedLabel()); $this->assertSame($label, $this->action->getParsedLabel());
} }
@ -108,7 +108,7 @@ class ActionTest extends TestCase {
/** /**
* @dataProvider dataSetParsedLabelInvalid * @dataProvider dataSetParsedLabelInvalid
* @param string $label * @param mixed $label
* *
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
@ -132,7 +132,7 @@ class ActionTest extends TestCase {
*/ */
public function testSetLink($link, $type) { public function testSetLink($link, $type) {
$this->assertSame('', $this->action->getLink()); $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($link, $this->action->getLink());
$this->assertSame($type, $this->action->getRequestType()); $this->assertSame($type, $this->action->getRequestType());
} }
@ -162,8 +162,8 @@ class ActionTest extends TestCase {
/** /**
* @dataProvider dataSetLinkInvalid * @dataProvider dataSetLinkInvalid
* @param string $link * @param mixed $link
* @param string $type * @param mixed $type
* *
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
@ -171,6 +171,44 @@ class ActionTest extends TestCase {
$this->action->setLink($link, $type); $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() { public function testIsValid() {
$this->assertFalse($this->action->isValid()); $this->assertFalse($this->action->isValid());
$this->assertFalse($this->action->isValidParsed()); $this->assertFalse($this->action->isValidParsed());

View File

@ -93,7 +93,7 @@ class NotificationTest extends TestCase {
*/ */
public function testSetApp($app) { public function testSetApp($app) {
$this->assertSame('', $this->notification->getApp()); $this->assertSame('', $this->notification->getApp());
$this->notification->setApp($app); $this->assertSame($this->notification, $this->notification->setApp($app));
$this->assertSame($app, $this->notification->getApp()); $this->assertSame($app, $this->notification->getApp());
} }
@ -121,7 +121,7 @@ class NotificationTest extends TestCase {
*/ */
public function testSetUser($user) { public function testSetUser($user) {
$this->assertSame('', $this->notification->getUser()); $this->assertSame('', $this->notification->getUser());
$this->notification->setUser($user); $this->assertSame($this->notification, $this->notification->setUser($user));
$this->assertSame($user, $this->notification->getUser()); $this->assertSame($user, $this->notification->getUser());
} }
@ -149,7 +149,7 @@ class NotificationTest extends TestCase {
*/ */
public function testSetTimestamp($timestamp) { public function testSetTimestamp($timestamp) {
$this->assertSame(0, $this->notification->getTimestamp()); $this->assertSame(0, $this->notification->getTimestamp());
$this->notification->setTimestamp($timestamp); $this->assertSame($this->notification, $this->notification->setTimestamp($timestamp));
$this->assertSame($timestamp, $this->notification->getTimestamp()); $this->assertSame($timestamp, $this->notification->getTimestamp());
} }
@ -182,7 +182,7 @@ class NotificationTest extends TestCase {
public function testSetObject($type, $id) { public function testSetObject($type, $id) {
$this->assertSame('', $this->notification->getObjectType()); $this->assertSame('', $this->notification->getObjectType());
$this->assertSame(0, $this->notification->getObjectId()); $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($type, $this->notification->getObjectType());
$this->assertSame($id, $this->notification->getObjectId()); $this->assertSame($id, $this->notification->getObjectId());
} }
@ -233,7 +233,7 @@ class NotificationTest extends TestCase {
public function testSetSubject($subject, $parameters) { public function testSetSubject($subject, $parameters) {
$this->assertSame('', $this->notification->getSubject()); $this->assertSame('', $this->notification->getSubject());
$this->assertSame([], $this->notification->getSubjectParameters()); $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($subject, $this->notification->getSubject());
$this->assertSame($parameters, $this->notification->getSubjectParameters()); $this->assertSame($parameters, $this->notification->getSubjectParameters());
} }
@ -262,7 +262,7 @@ class NotificationTest extends TestCase {
*/ */
public function testSetParsedSubject($subject) { public function testSetParsedSubject($subject) {
$this->assertSame('', $this->notification->getParsedSubject()); $this->assertSame('', $this->notification->getParsedSubject());
$this->notification->setParsedSubject($subject); $this->assertSame($this->notification, $this->notification->setParsedSubject($subject));
$this->assertSame($subject, $this->notification->getParsedSubject()); $this->assertSame($subject, $this->notification->getParsedSubject());
} }
@ -296,7 +296,7 @@ class NotificationTest extends TestCase {
public function testSetMessage($message, $parameters) { public function testSetMessage($message, $parameters) {
$this->assertSame('', $this->notification->getMessage()); $this->assertSame('', $this->notification->getMessage());
$this->assertSame([], $this->notification->getMessageParameters()); $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($message, $this->notification->getMessage());
$this->assertSame($parameters, $this->notification->getMessageParameters()); $this->assertSame($parameters, $this->notification->getMessageParameters());
} }
@ -325,7 +325,7 @@ class NotificationTest extends TestCase {
*/ */
public function testSetParsedMessage($message) { public function testSetParsedMessage($message) {
$this->assertSame('', $this->notification->getParsedMessage()); $this->assertSame('', $this->notification->getParsedMessage());
$this->notification->setParsedMessage($message); $this->assertSame($this->notification, $this->notification->setParsedMessage($message));
$this->assertSame($message, $this->notification->getParsedMessage()); $this->assertSame($message, $this->notification->getParsedMessage());
} }
@ -353,7 +353,7 @@ class NotificationTest extends TestCase {
*/ */
public function testSetLink($link) { public function testSetLink($link) {
$this->assertSame('', $this->notification->getLink()); $this->assertSame('', $this->notification->getLink());
$this->notification->setLink($link); $this->assertSame($this->notification, $this->notification->setLink($link));
$this->assertSame($link, $this->notification->getLink()); $this->assertSame($link, $this->notification->getLink());
} }
@ -387,7 +387,7 @@ class NotificationTest extends TestCase {
$action->expects($this->never()) $action->expects($this->never())
->method('isValidParsed'); ->method('isValidParsed');
$this->notification->addAction($action); $this->assertSame($this->notification, $this->notification->addAction($action));
$this->assertEquals([$action], $this->notification->getActions()); $this->assertEquals([$action], $this->notification->getActions());
$this->assertEquals([], $this->notification->getParsedActions()); $this->assertEquals([], $this->notification->getParsedActions());
@ -422,7 +422,7 @@ class NotificationTest extends TestCase {
->method('isPrimary') ->method('isPrimary')
->willReturn(true); ->willReturn(true);
$this->notification->addAction($action); $this->assertSame($this->notification, $this->notification->addAction($action));
$this->setExpectedException('\InvalidArgumentException'); $this->setExpectedException('\InvalidArgumentException');
$this->notification->addAction($action); $this->notification->addAction($action);
@ -439,7 +439,7 @@ class NotificationTest extends TestCase {
$action->expects($this->never()) $action->expects($this->never())
->method('isValid'); ->method('isValid');
$this->notification->addParsedAction($action); $this->assertSame($this->notification, $this->notification->addParsedAction($action));
$this->assertEquals([$action], $this->notification->getParsedActions()); $this->assertEquals([$action], $this->notification->getParsedActions());
$this->assertEquals([], $this->notification->getActions()); $this->assertEquals([], $this->notification->getActions());
@ -474,7 +474,7 @@ class NotificationTest extends TestCase {
->method('isPrimary') ->method('isPrimary')
->willReturn(true); ->willReturn(true);
$this->notification->addParsedAction($action); $this->assertSame($this->notification, $this->notification->addParsedAction($action));
$this->setExpectedException('\InvalidArgumentException'); $this->setExpectedException('\InvalidArgumentException');
$this->notification->addParsedAction($action); $this->notification->addParsedAction($action);