Update unit tests

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-07-16 13:32:44 +02:00
parent c3ef1cd90d
commit 565838da9c
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
6 changed files with 21 additions and 14 deletions

View File

@ -117,6 +117,9 @@ class NotificationsTest extends TestCase {
$comment->expects($this->any()) $comment->expects($this->any())
->method('getObjectType') ->method('getObjectType')
->willReturn('files'); ->willReturn('files');
$comment->expects($this->any())
->method('getId')
->willReturn('1234');
$this->commentsManager->expects($this->any()) $this->commentsManager->expects($this->any())
->method('get') ->method('get')
@ -192,6 +195,9 @@ class NotificationsTest extends TestCase {
$comment->expects($this->any()) $comment->expects($this->any())
->method('getObjectType') ->method('getObjectType')
->willReturn('files'); ->willReturn('files');
$comment->expects($this->any())
->method('getId')
->willReturn('1234');
$this->commentsManager->expects($this->any()) $this->commentsManager->expects($this->any())
->method('get') ->method('get')

View File

@ -91,6 +91,9 @@ class ListenerTest extends TestCase {
[ 'type' => 'user', 'id' => '23452-4333-54353-2342'], [ 'type' => 'user', 'id' => '23452-4333-54353-2342'],
[ 'type' => 'user', 'id' => 'yolo'], [ 'type' => 'user', 'id' => 'yolo'],
]); ]);
$comment->expects($this->atLeastOnce())
->method('getId')
->willReturn('1234');
/** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */
$event = $this->getMockBuilder(CommentsEvent::class) $event = $this->getMockBuilder(CommentsEvent::class)
@ -186,6 +189,9 @@ class ListenerTest extends TestCase {
$comment->expects($this->once()) $comment->expects($this->once())
->method('getMentions') ->method('getMentions')
->willReturn([[ 'type' => 'user', 'id' => 'foobar']]); ->willReturn([[ 'type' => 'user', 'id' => 'foobar']]);
$comment->expects($this->atLeastOnce())
->method('getId')
->willReturn('1234');
/** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */
$event = $this->getMockBuilder(CommentsEvent::class) $event = $this->getMockBuilder(CommentsEvent::class)

View File

@ -195,6 +195,9 @@ class NotifierTest extends TestCase {
->expects($this->any()) ->expects($this->any())
->method('getMentions') ->method('getMentions')
->willReturn([['type' => 'user', 'id' => 'you']]); ->willReturn([['type' => 'user', 'id' => 'you']]);
$this->comment->expects($this->atLeastOnce())
->method('getId')
->willReturn('1234');
$this->commentsManager $this->commentsManager
->expects($this->once()) ->expects($this->once())
@ -539,7 +542,7 @@ class NotifierTest extends TestCase {
} }
/** /**
* @expectedException \InvalidArgumentException * @expectedException \OCP\Notification\AlreadyProcessedException
*/ */
public function testPrepareUnresolvableFileID() { public function testPrepareUnresolvableFileID() {
$displayName = 'Huraga'; $displayName = 'Huraga';

View File

@ -30,6 +30,7 @@ use OCP\IGroupManager;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
use Test\TestCase; use Test\TestCase;
@ -112,21 +113,12 @@ class NotifierTest extends TestCase {
->method('getObjectId') ->method('getObjectId')
->willReturn($versionNotification); ->willReturn($versionNotification);
if ($exception) {
$this->notificationManager->expects($this->once())
->method('markProcessed')
->with($notification);
} else {
$this->notificationManager->expects($this->never())
->method('markProcessed');
}
try { try {
self::invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, $versionInstalled]); self::invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, $versionInstalled]);
$this->assertFalse($exception); $this->assertFalse($exception);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertTrue($exception); $this->assertTrue($exception);
$this->assertInstanceOf('InvalidArgumentException', $e); $this->assertInstanceOf(AlreadyProcessedException::class, $e);
} }
} }
} }

View File

@ -61,7 +61,7 @@ class RemoteWipeNotificationsListener implements IEventListener {
$notification->setApp('auth') $notification->setApp('auth')
->setUser($token->getUID()) ->setUser($token->getUID())
->setDateTime($this->timeFactory->getDateTime()) ->setDateTime($this->timeFactory->getDateTime())
->setObject('token', $token->getId()) ->setObject('token', (string) $token->getId())
->setSubject($event, [ ->setSubject($event, [
'name' => $token->getName(), 'name' => $token->getName(),
]); ]);

View File

@ -92,7 +92,7 @@ class RemoteWipeNotificationListenerTests extends TestCase {
$token->method('getId')->willReturn(123); $token->method('getId')->willReturn(123);
$notification->expects($this->once()) $notification->expects($this->once())
->method('setObject') ->method('setObject')
->with('token', 123) ->with('token', '123')
->willReturnSelf(); ->willReturnSelf();
$token->method('getName')->willReturn('Token 1'); $token->method('getName')->willReturn('Token 1');
$notification->expects($this->once()) $notification->expects($this->once())
@ -132,7 +132,7 @@ class RemoteWipeNotificationListenerTests extends TestCase {
$token->method('getId')->willReturn(123); $token->method('getId')->willReturn(123);
$notification->expects($this->once()) $notification->expects($this->once())
->method('setObject') ->method('setObject')
->with('token', 123) ->with('token', '123')
->willReturnSelf(); ->willReturnSelf();
$token->method('getName')->willReturn('Token 1'); $token->method('getName')->willReturn('Token 1');
$notification->expects($this->once()) $notification->expects($this->once())