Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions apps/comments/tests/Unit/Controller/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function testViewSuccess() {

$file = $this->createMock(Node::class);
$folder = $this->createMock(Folder::class);
$user = $this->createMock(IUser::class);

$this->rootFolder->expects($this->once())
->method('getUserFolder')
Expand All @@ -136,7 +137,11 @@ public function testViewSuccess() {

$this->session->expects($this->once())
->method('getUser')
->willReturn($this->createMock(IUser::class));
->willReturn($user);

$user->expects($this->any())
->method('getUID')
->willReturn('user');

$notification = $this->createMock(INotification::class);
$notification->expects($this->any())
Expand All @@ -163,9 +168,15 @@ public function testViewInvalidComment() {
$this->rootFolder->expects($this->never())
->method('getUserFolder');

$user = $this->createMock(IUser::class);

$this->session->expects($this->once())
->method('getUser')
->willReturn($this->createMock(IUser::class));
->willReturn($user);

$user->expects($this->any())
->method('getUID')
->willReturn('user');

$this->notificationManager->expects($this->never())
->method('createNotification');
Expand Down Expand Up @@ -197,9 +208,15 @@ public function testViewNoFile() {
->method('getById')
->willReturn([]);

$user = $this->createMock(IUser::class);

$this->session->expects($this->once())
->method('getUser')
->willReturn($this->createMock(IUser::class));
->willReturn($user);

$user->expects($this->any())
->method('getUID')
->willReturn('user');

$notification = $this->createMock(INotification::class);
$notification->expects($this->any())
Expand Down
40 changes: 20 additions & 20 deletions lib/private/Notification/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function __construct(IValidator $richValidator) {
* @since 8.2.0
*/
public function setApp(string $app) {
if (!is_string($app) || $app === '' || isset($app[32])) {
if (trim($app) === '' || isset($app[32])) {
throw new \InvalidArgumentException('The given app name is invalid');
}
$this->app = $app;
Expand All @@ -157,7 +157,7 @@ public function getApp() {
* @since 8.2.0
*/
public function setUser(string $user) {
if (!is_string($user) || $user === '' || isset($user[64])) {
if (trim($user) === '' || isset($user[64])) {
throw new \InvalidArgumentException('The given user id is invalid');
}
$this->user = $user;
Expand Down Expand Up @@ -201,8 +201,8 @@ public function getDateTime() {
* @throws \InvalidArgumentException if the object type or id is invalid
* @since 8.2.0 - 9.0.0: Type of $id changed to string
*/
public function setObject($type, $id) {
if (!is_string($type) || $type === '' || isset($type[64])) {
public function setObject(string $type, $id) {
if (trim($type) === '' || isset($type[64])) {
throw new \InvalidArgumentException('The given object type is invalid');
}
$this->objectType = $type;
Expand Down Expand Up @@ -237,8 +237,8 @@ public function getObjectId() {
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 8.2.0
*/
public function setSubject($subject, array $parameters = []) {
if (!is_string($subject) || $subject === '' || isset($subject[64])) {
public function setSubject(string $subject, array $parameters = []) {
if (trim($subject) === '' || isset($subject[64])) {
throw new \InvalidArgumentException('The given subject is invalid');
}

Expand Down Expand Up @@ -270,8 +270,8 @@ public function getSubjectParameters() {
* @throws \InvalidArgumentException if the subject is invalid
* @since 8.2.0
*/
public function setParsedSubject($subject) {
if (!is_string($subject) || $subject === '') {
public function setParsedSubject(string $subject) {
if (trim($subject) === '') {
throw new \InvalidArgumentException('The given parsed subject is invalid');
}
$this->subjectParsed = $subject;
Expand All @@ -293,8 +293,8 @@ public function getParsedSubject() {
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 11.0.0
*/
public function setRichSubject($subject, array $parameters = []) {
if (!is_string($subject) || $subject === '') {
public function setRichSubject(string $subject, array $parameters = []) {
if (trim($subject) === '') {
throw new \InvalidArgumentException('The given parsed subject is invalid');
}

Expand Down Expand Up @@ -327,8 +327,8 @@ public function getRichSubjectParameters() {
* @throws \InvalidArgumentException if the message or parameters are invalid
* @since 8.2.0
*/
public function setMessage($message, array $parameters = []) {
if (!is_string($message) || $message === '' || isset($message[64])) {
public function setMessage(string $message, array $parameters = []) {
if (trim($message) === '' || isset($message[64])) {
throw new \InvalidArgumentException('The given message is invalid');
}

Expand Down Expand Up @@ -360,8 +360,8 @@ public function getMessageParameters() {
* @throws \InvalidArgumentException if the message is invalid
* @since 8.2.0
*/
public function setParsedMessage($message) {
if (!is_string($message) || $message === '') {
public function setParsedMessage(string $message) {
if (trim($message) === '') {
throw new \InvalidArgumentException('The given parsed message is invalid');
}
$this->messageParsed = $message;
Expand All @@ -383,8 +383,8 @@ public function getParsedMessage() {
* @throws \InvalidArgumentException if the message or parameters are invalid
* @since 11.0.0
*/
public function setRichMessage($message, array $parameters = []) {
if (!is_string($message) || $message === '') {
public function setRichMessage(string $message, array $parameters = []) {
if (trim($message) === '') {
throw new \InvalidArgumentException('The given parsed message is invalid');
}

Expand Down Expand Up @@ -416,8 +416,8 @@ public function getRichMessageParameters() {
* @throws \InvalidArgumentException if the link is invalid
* @since 8.2.0
*/
public function setLink($link) {
if (!is_string($link) || $link === '' || isset($link[4000])) {
public function setLink(string $link) {
if (trim($link) === '' || isset($link[4000])) {
throw new \InvalidArgumentException('The given link is invalid');
}
$this->link = $link;
Expand All @@ -438,8 +438,8 @@ public function getLink() {
* @throws \InvalidArgumentException if the icon is invalid
* @since 11.0.0
*/
public function setIcon($icon) {
if (!is_string($icon) || $icon === '' || isset($icon[4000])) {
public function setIcon(string $icon) {
if (trim($icon) === '' || isset($icon[4000])) {
throw new \InvalidArgumentException('The given icon is invalid');
}
$this->icon = $icon;
Expand Down
18 changes: 9 additions & 9 deletions lib/public/Notification/INotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getDateTime();
* @throws \InvalidArgumentException if the object type or id is invalid
* @since 9.0.0
*/
public function setObject($type, $id);
public function setObject(string $type, $id);

/**
* @return string
Expand All @@ -101,7 +101,7 @@ public function getObjectId();
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 9.0.0
*/
public function setSubject($subject, array $parameters = []);
public function setSubject(string $subject, array $parameters = []);

/**
* @return string
Expand Down Expand Up @@ -132,7 +132,7 @@ public function getSubjectParameters();
* @throws \InvalidArgumentException if the subject is invalid
* @since 9.0.0
*/
public function setParsedSubject($subject);
public function setParsedSubject(string $subject);

/**
* @return string
Expand All @@ -157,7 +157,7 @@ public function getParsedSubject();
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 11.0.0
*/
public function setRichSubject($subject, array $parameters = []);
public function setRichSubject(string $subject, array $parameters = []);

/**
* @return string
Expand All @@ -178,7 +178,7 @@ public function getRichSubjectParameters();
* @throws \InvalidArgumentException if the message or parameters are invalid
* @since 9.0.0
*/
public function setMessage($message, array $parameters = []);
public function setMessage(string $message, array $parameters = []);

/**
* @return string
Expand Down Expand Up @@ -209,7 +209,7 @@ public function getMessageParameters();
* @throws \InvalidArgumentException if the message is invalid
* @since 9.0.0
*/
public function setParsedMessage($message);
public function setParsedMessage(string $message);

/**
* @return string
Expand All @@ -234,7 +234,7 @@ public function getParsedMessage();
* @throws \InvalidArgumentException if the message or parameters are invalid
* @since 11.0.0
*/
public function setRichMessage($message, array $parameters = []);
public function setRichMessage(string $message, array $parameters = []);

/**
* @return string
Expand All @@ -254,7 +254,7 @@ public function getRichMessageParameters();
* @throws \InvalidArgumentException if the link is invalid
* @since 9.0.0
*/
public function setLink($link);
public function setLink(string $link);

/**
* @return string
Expand All @@ -268,7 +268,7 @@ public function getLink();
* @throws \InvalidArgumentException if the icon is invalid
* @since 11.0.0
*/
public function setIcon($icon);
public function setIcon(string $icon);

/**
* @return string
Expand Down
49 changes: 42 additions & 7 deletions tests/lib/Notification/NotificationTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);
/**
* @author Joas Schilling <[email protected]>
*
Expand Down Expand Up @@ -43,6 +44,7 @@ public function setUp() {
protected function dataValidString($maxLength) {
$dataSets = [
['test1'],
['1564'],
[str_repeat('a', 1)],
];
if ($maxLength !== false) {
Expand All @@ -53,20 +55,24 @@ protected function dataValidString($maxLength) {

protected function dataInvalidString($maxLength) {
$dataSets = [
[true],
[false],
[0],
[1],
[''],
[[]],
['']
];
if ($maxLength !== false) {
$dataSets[] = [str_repeat('a', $maxLength + 1)];
$dataSets[] = [[str_repeat('a', $maxLength + 1)]];
}
return $dataSets;
}

protected function dataInvalidStringType() {
return [
[true],
[false],
[16412],
[[]],
[null],
];
}

protected function dataInvalidInt() {
return [
[true],
Expand Down Expand Up @@ -98,6 +104,10 @@ public function dataSetAppInvalid() {
return $this->dataInvalidString(32);
}

public function dataSetAppInvalidType() {
return $this->dataInvalidStringType();
}

/**
* @dataProvider dataSetAppInvalid
* @param mixed $app
Expand All @@ -108,6 +118,17 @@ public function testSetAppInvalid($app) {
$this->notification->setApp($app);
}

/**
* @dataProvider dataSetAppInvalidType
* @param mixed $app
*
* @expectedException \TypeError
*/
public function testSetAppInvalidType($app) {
$this->notification->setApp($app);
}


public function dataSetUser() {
return $this->dataValidString(64);
}
Expand All @@ -126,6 +147,10 @@ public function dataSetUserInvalid() {
return $this->dataInvalidString(64);
}

public function dataSetUserInvalidType() {
return $this->dataInvalidStringType();
}

/**
* @dataProvider dataSetUserInvalid
* @param mixed $user
Expand All @@ -136,6 +161,16 @@ public function testSetUserInvalid($user) {
$this->notification->setUser($user);
}

/**
* @dataProvider dataSetUserInvalidType
* @param mixed $user
*
* @expectedException \TypeError
*/
public function testSetUserInvalidType($user) {
$this->notification->setUser($user);
}

public function dataSetDateTime() {
$past = new \DateTime();
$past->sub(new \DateInterval('P1Y'));
Expand Down