summaryrefslogtreecommitdiffstats
path: root/tests/lib/Comments/CommentTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Comments/CommentTest.php')
-rw-r--r--tests/lib/Comments/CommentTest.php57
1 files changed, 51 insertions, 6 deletions
diff --git a/tests/lib/Comments/CommentTest.php b/tests/lib/Comments/CommentTest.php
index ea10c52ae17..10ec4bae7d5 100644
--- a/tests/lib/Comments/CommentTest.php
+++ b/tests/lib/Comments/CommentTest.php
@@ -2,13 +2,14 @@
namespace Test\Comments;
+use OC\Comments\Comment;
use OCP\Comments\IComment;
use Test\TestCase;
class CommentTest extends TestCase {
public function testSettersValidInput() {
- $comment = new \OC\Comments\Comment();
+ $comment = new Comment();
$id = 'comment23';
$parentId = 'comment11.5';
@@ -51,14 +52,14 @@ class CommentTest extends TestCase {
* @expectedException \OCP\Comments\IllegalIDChangeException
*/
public function testSetIdIllegalInput() {
- $comment = new \OC\Comments\Comment();
+ $comment = new Comment();
$comment->setId('c23');
$comment->setId('c17');
}
public function testResetId() {
- $comment = new \OC\Comments\Comment();
+ $comment = new Comment();
$comment->setId('c23');
$comment->setId('');
@@ -82,7 +83,7 @@ class CommentTest extends TestCase {
* @expectedException \InvalidArgumentException
*/
public function testSimpleSetterInvalidInput($field, $input) {
- $comment = new \OC\Comments\Comment();
+ $comment = new Comment();
$setter = 'set' . $field;
$comment->$setter($input);
@@ -106,7 +107,7 @@ class CommentTest extends TestCase {
* @expectedException \InvalidArgumentException
*/
public function testSetRoleInvalidInput($role, $type, $id){
- $comment = new \OC\Comments\Comment();
+ $comment = new Comment();
$setter = 'set' . $role;
$comment->$setter($type, $id);
}
@@ -115,11 +116,55 @@ class CommentTest extends TestCase {
* @expectedException \OCP\Comments\MessageTooLongException
*/
public function testSetUberlongMessage() {
- $comment = new \OC\Comments\Comment();
+ $comment = new Comment();
$msg = str_pad('', IComment::MAX_MESSAGE_LENGTH + 1, 'x');
$comment->setMessage($msg);
}
+ public function mentionsProvider() {
+ return [
+ [
+ '@alice @bob look look, a cook!', ['alice', 'bob']
+ ],
+ [
+ 'no mentions in this message', []
+ ],
+ [
+ '@alice @bob look look, a duplication @alice test @bob!', ['alice', 'bob']
+ ],
+ [
+ '@alice is the author, but notify @bob!', ['bob'], 'alice'
+ ],
+ [
+ '@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!',
+ ['foobar', 'barfoo', 'foo@bar.com', 'bar@foo.org@foobar.io', '23452-4333-54353-2342', 'yolo']
+ ]
+
+ ];
+ }
+
+ /**
+ * @dataProvider mentionsProvider
+ */
+ public function testMentions($message, $expectedUids, $author = null) {
+ $comment = new Comment();
+ $comment->setMessage($message);
+ if(!is_null($author)) {
+ $comment->setActor('user', $author);
+ }
+ $mentions = $comment->getMentions();
+ while($mention = array_shift($mentions)) {
+ $uid = array_shift($expectedUids);
+ $this->assertSame('user', $mention['type']);
+ $this->assertSame($uid, $mention['id']);
+ $this->assertNotSame($author, $mention['id']);
+ }
+ $this->assertEmpty($mentions);
+ $this->assertEmpty($expectedUids);
+ }
+
}