|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
} |