Make user mentions great again
This commit is contained in:
@@ -33,5 +33,7 @@ class CommentEventBuilderTest extends Base
|
||||
$this->assertInstanceOf('Kanboard\Event\CommentEvent', $event);
|
||||
$this->assertNotEmpty($event['comment']);
|
||||
$this->assertNotEmpty($event['task']);
|
||||
$this->assertEquals(1, $event->getTaskId());
|
||||
$this->assertEquals(1, $event->getProjectId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,5 +29,7 @@ class ProjectFileEventBuilderTest extends Base
|
||||
$this->assertInstanceOf('Kanboard\Event\ProjectFileEvent', $event);
|
||||
$this->assertNotEmpty($event['file']);
|
||||
$this->assertNotEmpty($event['project']);
|
||||
$this->assertNull($event->getTaskId());
|
||||
$this->assertEquals(1, $event->getProjectId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,5 +58,7 @@ class SubtaskEventBuilderTest extends Base
|
||||
$this->assertCount(2, $event['changes']);
|
||||
$this->assertEquals('new title', $event['changes']['title']);
|
||||
$this->assertEquals(1, $event['changes']['user_id']);
|
||||
$this->assertEquals(1, $event->getTaskId());
|
||||
$this->assertEquals(1, $event->getProjectId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ class TaskEventBuilderTest extends Base
|
||||
$this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
|
||||
$this->assertNotEmpty($event['task']);
|
||||
$this->assertEquals(1, $event['task_id']);
|
||||
$this->assertEquals(1, $event->getTaskId());
|
||||
$this->assertEquals(1, $event->getProjectId());
|
||||
$this->assertEquals(array('title' => 'after'), $event['changes']);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,5 +32,7 @@ class TaskFileEventBuilderTest extends Base
|
||||
$this->assertInstanceOf('Kanboard\Event\TaskFileEvent', $event);
|
||||
$this->assertNotEmpty($event['file']);
|
||||
$this->assertNotEmpty($event['task']);
|
||||
$this->assertEquals(1, $event->getTaskId());
|
||||
$this->assertEquals(1, $event->getProjectId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ class TaskLinkEventBuilderTest extends Base
|
||||
$this->assertInstanceOf('Kanboard\Event\TaskLinkEvent', $event);
|
||||
$this->assertNotEmpty($event['task_link']);
|
||||
$this->assertNotEmpty($event['task']);
|
||||
$this->assertEquals(1, $event->getTaskId());
|
||||
$this->assertEquals(1, $event->getProjectId());
|
||||
}
|
||||
|
||||
public function testBuildTitle()
|
||||
|
||||
@@ -47,12 +47,12 @@ class TextHelperTest extends Base
|
||||
public function testMarkdownUserLink()
|
||||
{
|
||||
$h = new TextHelper($this->container);
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>,</p>', $h->markdown('Text @admin,'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>!</p>', $h->markdown('Text @admin!'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>? </p>', $h->markdown('Text @admin? '));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>.</p>', $h->markdown('Text @admin.'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>: test</p>', $h->markdown('Text @admin: test'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>,</p>', $h->markdown('Text @admin,'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>!</p>', $h->markdown('Text @admin!'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>? </p>', $h->markdown('Text @admin? '));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>.</p>', $h->markdown('Text @admin.'));
|
||||
$this->assertEquals('<p>Text <a href="http://localhost/?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>: test</p>', $h->markdown('Text @admin: test'));
|
||||
$this->assertEquals('<p>Text @admin @notfound</p>', $h->markdown('Text @admin @notfound', true));
|
||||
}
|
||||
|
||||
|
||||
@@ -49,4 +49,46 @@ class CommentEventJobTest extends Base
|
||||
$this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called);
|
||||
$this->assertArrayHasKey(CommentModel::EVENT_DELETE.'.closure', $called);
|
||||
}
|
||||
|
||||
public function testThatUserMentionJobIsCalled()
|
||||
{
|
||||
$comment = 'some comment';
|
||||
|
||||
$this->container['queueManager'] = $this
|
||||
->getMockBuilder('\Kanboard\Core\Queue\QueueManager')
|
||||
->setConstructorArgs(array($this->container))
|
||||
->setMethods(array(
|
||||
'push',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->container['userMentionJob'] = $this
|
||||
->getMockBuilder('\Kanboard\Job\UserMentionJob')
|
||||
->setConstructorArgs(array($this->container))
|
||||
->setMethods(array(
|
||||
'withParams',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->container['queueManager']
|
||||
->expects($this->any())
|
||||
->method('push');
|
||||
|
||||
$this->container['userMentionJob']
|
||||
->expects($this->once())
|
||||
->method('withParams')
|
||||
->with($comment, CommentModel::EVENT_USER_MENTION, $this->anything())
|
||||
->will($this->returnValue($this->container['userMentionJob']));
|
||||
|
||||
$commentModel = new CommentModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$commentEventJob = new CommentEventJob($this->container);
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => $comment, 'user_id' => 1)));
|
||||
|
||||
$commentEventJob->execute(1, CommentModel::EVENT_CREATE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,4 +186,44 @@ class TaskEventJobTest extends Base
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.closure', $called);
|
||||
}
|
||||
|
||||
public function testThatUserMentionJobIsCalled()
|
||||
{
|
||||
$description = 'something';
|
||||
|
||||
$this->container['queueManager'] = $this
|
||||
->getMockBuilder('\Kanboard\Core\Queue\QueueManager')
|
||||
->setConstructorArgs(array($this->container))
|
||||
->setMethods(array(
|
||||
'push',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->container['userMentionJob'] = $this
|
||||
->getMockBuilder('\Kanboard\Job\UserMentionJob')
|
||||
->setConstructorArgs(array($this->container))
|
||||
->setMethods(array(
|
||||
'withParams',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->container['queueManager']
|
||||
->expects($this->any())
|
||||
->method('push');
|
||||
|
||||
$this->container['userMentionJob']
|
||||
->expects($this->once())
|
||||
->method('withParams')
|
||||
->with($description, TaskModel::EVENT_USER_MENTION, $this->anything())
|
||||
->will($this->returnValue($this->container['userMentionJob']));
|
||||
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskEventJob = new TaskEventJob($this->container);
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'description' => $description, 'project_id' => 1)));
|
||||
|
||||
$taskEventJob->execute(1, array(TaskModel::EVENT_CREATE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Kanboard\Core\Security\Role;
|
||||
use Kanboard\Event\TaskEvent;
|
||||
use Kanboard\Job\UserMentionJob;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\ProjectUserRoleModel;
|
||||
use Kanboard\Model\TaskModel;
|
||||
use Kanboard\Model\UserModel;
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Kanboard\Core\Security\Role;
|
||||
use Kanboard\Event\GenericEvent;
|
||||
use Kanboard\Model\UserModel;
|
||||
use Kanboard\Model\TaskModel;
|
||||
use Kanboard\Model\TaskCreationModel;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\ProjectUserRoleModel;
|
||||
use Kanboard\Model\UserMentionModel;
|
||||
|
||||
class UserMentionTest extends Base
|
||||
class UserMentionJobTest extends Base
|
||||
{
|
||||
public function testGetMentionedUsersWithNoMentions()
|
||||
{
|
||||
$userModel = new UserModel($this->container);
|
||||
$userMentionModel = new UserMentionModel($this->container);
|
||||
$userMentionJob = new UserMentionJob($this->container);
|
||||
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
|
||||
$this->assertEmpty($userMentionModel->getMentionedUsers('test'));
|
||||
$this->assertEmpty($userMentionJob->getMentionedUsers('test'));
|
||||
}
|
||||
|
||||
public function testGetMentionedUsersWithNotficationDisabled()
|
||||
{
|
||||
$userModel = new UserModel($this->container);
|
||||
$userMentionModel = new UserMentionModel($this->container);
|
||||
$userMentionJob = new UserMentionJob($this->container);
|
||||
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
|
||||
$this->assertEmpty($userMentionModel->getMentionedUsers('test @user1'));
|
||||
$this->assertEmpty($userMentionJob->getMentionedUsers('test @user1'));
|
||||
}
|
||||
|
||||
public function testGetMentionedUsersWithNotficationEnabled()
|
||||
{
|
||||
$userModel = new UserModel($this->container);
|
||||
$userMentionModel = new UserMentionModel($this->container);
|
||||
$userMentionJob = new UserMentionJob($this->container);
|
||||
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1)));
|
||||
|
||||
$users = $userMentionModel->getMentionedUsers('test @user2');
|
||||
$users = $userMentionJob->getMentionedUsers('test @user2');
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertEquals('user2', $users[0]['username']);
|
||||
$this->assertEquals('Foobar', $users[0]['name']);
|
||||
$this->assertEquals('', $users[0]['email']);
|
||||
$this->assertEquals('', $users[0]['language']);
|
||||
}
|
||||
|
||||
public function testGetMentionedUsersWithNotficationEnabledAndPunctuationMarks()
|
||||
{
|
||||
$userModel = new UserModel($this->container);
|
||||
$userMentionJob = new UserMentionJob($this->container);
|
||||
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1)));
|
||||
|
||||
$users = $userMentionJob->getMentionedUsers('test @user2, test');
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertEquals('user2', $users[0]['username']);
|
||||
$this->assertEquals('Foobar', $users[0]['name']);
|
||||
@@ -51,12 +66,12 @@ class UserMentionTest extends Base
|
||||
{
|
||||
$this->container['sessionStorage']->user = array('id' => 3);
|
||||
$userModel = new UserModel($this->container);
|
||||
$userMentionModel = new UserMentionModel($this->container);
|
||||
$userMentionJob = new UserMentionJob($this->container);
|
||||
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1)));
|
||||
|
||||
$this->assertEmpty($userMentionModel->getMentionedUsers('test @user2'));
|
||||
$this->assertEmpty($userMentionJob->getMentionedUsers('test @user2'));
|
||||
}
|
||||
|
||||
public function testFireEventsWithMultipleMentions()
|
||||
@@ -64,8 +79,8 @@ class UserMentionTest extends Base
|
||||
$projectUserRoleModel = new ProjectUserRoleModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$userModel = new UserModel($this->container);
|
||||
$userMentionModel = new UserMentionModel($this->container);
|
||||
$event = new GenericEvent(array('project_id' => 1));
|
||||
$userMentionJob = new UserMentionJob($this->container);
|
||||
$event = new TaskEvent(array('task' => array('project_id' => 1)));
|
||||
|
||||
$this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1)));
|
||||
$this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1)));
|
||||
@@ -75,35 +90,10 @@ class UserMentionTest extends Base
|
||||
|
||||
$this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention'));
|
||||
|
||||
$userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event);
|
||||
$userMentionJob->execute('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event);
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called);
|
||||
}
|
||||
|
||||
public function testFireEventsWithNoProjectId()
|
||||
{
|
||||
$projectUserRoleModel = new ProjectUserRoleModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$userModel = new UserModel($this->container);
|
||||
$userMentionModel = new UserMentionModel($this->container);
|
||||
$event = new GenericEvent(array('task_id' => 1));
|
||||
|
||||
$this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1)));
|
||||
$this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1)));
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
|
||||
$this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
|
||||
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'Task 1')));
|
||||
|
||||
$this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention'));
|
||||
|
||||
$userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event);
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called);
|
||||
$this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionJobTest::onUserMention', $called);
|
||||
}
|
||||
|
||||
public function onUserMention($event)
|
||||
Reference in New Issue
Block a user