diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2016-10-14 00:19:31 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2016-10-19 00:33:55 +0200 |
commit | fea3e20a805de12546312c68557ddbd8498b9414 (patch) | |
tree | 4cc3f481c51f3feab18c29164a57acbe70d86f5f /apps/comments/tests | |
parent | e115bf96e742909b78150d04305b67196b94115c (diff) | |
download | nextcloud-server-fea3e20a805de12546312c68557ddbd8498b9414.tar.gz nextcloud-server-fea3e20a805de12546312c68557ddbd8498b9414.zip |
move mention extraction to (I)Comment and report mentions via DAV
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/comments/tests')
-rw-r--r-- | apps/comments/tests/Unit/Notification/ListenerTest.php | 142 |
1 files changed, 13 insertions, 129 deletions
diff --git a/apps/comments/tests/Unit/Notification/ListenerTest.php b/apps/comments/tests/Unit/Notification/ListenerTest.php index 12f388fcff9..3007b78cb3d 100644 --- a/apps/comments/tests/Unit/Notification/ListenerTest.php +++ b/apps/comments/tests/Unit/Notification/ListenerTest.php @@ -72,10 +72,6 @@ class ListenerTest extends TestCase { * @param string $notificationMethod */ public function testEvaluate($eventType, $notificationMethod) { - $message = '@foobar and @barfoo you should know, @foo@bar.com is valid' . - ' and so is @bar@foo.org@foobar.io I hope that clarifies everything.' . - ' cc @23452-4333-54353-2342 @yolo!'; - /** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */ $comment = $this->getMockBuilder('\OCP\Comments\IComment')->getMock(); $comment->expects($this->any()) @@ -85,8 +81,15 @@ class ListenerTest extends TestCase { ->method('getCreationDateTime') ->will($this->returnValue(new \DateTime())); $comment->expects($this->once()) - ->method('getMessage') - ->will($this->returnValue($message)); + ->method('getMentions') + ->willReturn([ + [ 'type' => 'user', 'id' => 'foobar'], + [ 'type' => 'user', 'id' => 'barfoo'], + [ 'type' => 'user', 'id' => 'foo@bar.com'], + [ 'type' => 'user', 'id' => 'bar@foo.org@foobar.io'], + [ 'type' => 'user', 'id' => '23452-4333-54353-2342'], + [ 'type' => 'user', 'id' => 'yolo'], + ]); /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder('\OCP\Comments\CommentsEvent') @@ -134,8 +137,6 @@ class ListenerTest extends TestCase { * @param string $eventType */ public function testEvaluateNoMentions($eventType) { - $message = 'a boring comment without mentions'; - /** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */ $comment = $this->getMockBuilder('\OCP\Comments\IComment')->getMock(); $comment->expects($this->any()) @@ -145,8 +146,8 @@ class ListenerTest extends TestCase { ->method('getCreationDateTime') ->will($this->returnValue(new \DateTime())); $comment->expects($this->once()) - ->method('getMessage') - ->will($this->returnValue($message)); + ->method('getMentions') + ->willReturn([]); /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder('\OCP\Comments\CommentsEvent') @@ -173,8 +174,6 @@ class ListenerTest extends TestCase { } public function testEvaluateUserDoesNotExist() { - $message = '@foobar bla bla bla'; - /** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */ $comment = $this->getMockBuilder('\OCP\Comments\IComment')->getMock(); $comment->expects($this->any()) @@ -184,8 +183,8 @@ class ListenerTest extends TestCase { ->method('getCreationDateTime') ->will($this->returnValue(new \DateTime())); $comment->expects($this->once()) - ->method('getMessage') - ->will($this->returnValue($message)); + ->method('getMentions') + ->willReturn([[ 'type' => 'user', 'id' => 'foobar']]); /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder('\OCP\Comments\CommentsEvent') @@ -221,119 +220,4 @@ class ListenerTest extends TestCase { $this->listener->evaluate($event); } - - /** - * @dataProvider eventProvider - * @param string $eventType - * @param string $notificationMethod - */ - public function testEvaluateOneMentionPerUser($eventType, $notificationMethod) { - $message = '@foobar bla bla bla @foobar'; - - /** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */ - $comment = $this->getMockBuilder('\OCP\Comments\IComment')->getMock(); - $comment->expects($this->any()) - ->method('getObjectType') - ->will($this->returnValue('files')); - $comment->expects($this->any()) - ->method('getCreationDateTime') - ->will($this->returnValue(new \DateTime())); - $comment->expects($this->once()) - ->method('getMessage') - ->will($this->returnValue($message)); - - /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ - $event = $this->getMockBuilder('\OCP\Comments\CommentsEvent') - ->disableOriginalConstructor() - ->getMock(); - $event->expects($this->once()) - ->method('getComment') - ->will($this->returnValue($comment)); - $event->expects(($this->any())) - ->method(('getEvent')) - ->will($this->returnValue($eventType)); - - /** @var INotification|\PHPUnit_Framework_MockObject_MockObject $notification */ - $notification = $this->getMockBuilder('\OCP\Notification\INotification')->getMock(); - $notification->expects($this->any()) - ->method($this->anything()) - ->will($this->returnValue($notification)); - $notification->expects($this->once()) - ->method('setUser'); - - $this->notificationManager->expects($this->once()) - ->method('createNotification') - ->will($this->returnValue($notification)); - $this->notificationManager->expects($this->once()) - ->method($notificationMethod) - ->with($this->isInstanceOf('\OCP\Notification\INotification')); - - $this->userManager->expects($this->once()) - ->method('userExists') - ->withConsecutive( - ['foobar'] - ) - ->will($this->returnValue(true)); - - $this->listener->evaluate($event); - } - - /** - * @dataProvider eventProvider - * @param string $eventType - */ - public function testEvaluateNoSelfMention($eventType) { - $message = '@foobar bla bla bla'; - - /** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */ - $comment = $this->getMockBuilder('\OCP\Comments\IComment')->getMock(); - $comment->expects($this->any()) - ->method('getObjectType') - ->will($this->returnValue('files')); - $comment->expects($this->any()) - ->method('getActorType') - ->will($this->returnValue('users')); - $comment->expects($this->any()) - ->method('getActorId') - ->will($this->returnValue('foobar')); - $comment->expects($this->any()) - ->method('getCreationDateTime') - ->will($this->returnValue(new \DateTime())); - $comment->expects($this->once()) - ->method('getMessage') - ->will($this->returnValue($message)); - - /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ - $event = $this->getMockBuilder('\OCP\Comments\CommentsEvent') - ->disableOriginalConstructor() - ->getMock(); - $event->expects($this->once()) - ->method('getComment') - ->will($this->returnValue($comment)); - $event->expects(($this->any())) - ->method(('getEvent')) - ->will($this->returnValue($eventType)); - - /** @var INotification|\PHPUnit_Framework_MockObject_MockObject $notification */ - $notification = $this->getMockBuilder('\OCP\Notification\INotification')->getMock(); - $notification->expects($this->any()) - ->method($this->anything()) - ->will($this->returnValue($notification)); - $notification->expects($this->never()) - ->method('setUser'); - - $this->notificationManager->expects($this->once()) - ->method('createNotification') - ->will($this->returnValue($notification)); - $this->notificationManager->expects($this->never()) - ->method('notify'); - $this->notificationManager->expects($this->never()) - ->method('markProcessed'); - - $this->userManager->expects($this->never()) - ->method('userExists'); - - $this->listener->evaluate($event); - } - } |