summaryrefslogtreecommitdiff
path: root/tests/units/Job
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Job')
-rw-r--r--tests/units/Job/CommentEventJobTest.php42
-rw-r--r--tests/units/Job/TaskEventJobTest.php40
-rw-r--r--tests/units/Job/UserMentionJobTest.php110
3 files changed, 192 insertions, 0 deletions
diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php
index 8571af8e..b830b2b8 100644
--- a/tests/units/Job/CommentEventJobTest.php
+++ b/tests/units/Job/CommentEventJobTest.php
@@ -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);
+ }
}
diff --git a/tests/units/Job/TaskEventJobTest.php b/tests/units/Job/TaskEventJobTest.php
index c399faad..bfd7bc55 100644
--- a/tests/units/Job/TaskEventJobTest.php
+++ b/tests/units/Job/TaskEventJobTest.php
@@ -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));
+ }
}
diff --git a/tests/units/Job/UserMentionJobTest.php b/tests/units/Job/UserMentionJobTest.php
new file mode 100644
index 00000000..04ffa0d3
--- /dev/null
+++ b/tests/units/Job/UserMentionJobTest.php
@@ -0,0 +1,110 @@
+<?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';
+
+class UserMentionJobTest extends Base
+{
+ public function testGetMentionedUsersWithNoMentions()
+ {
+ $userModel = new UserModel($this->container);
+ $userMentionJob = new UserMentionJob($this->container);
+
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+ $this->assertEmpty($userMentionJob->getMentionedUsers('test'));
+ }
+
+ public function testGetMentionedUsersWithNotficationDisabled()
+ {
+ $userModel = new UserModel($this->container);
+ $userMentionJob = new UserMentionJob($this->container);
+
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+ $this->assertEmpty($userMentionJob->getMentionedUsers('test @user1'));
+ }
+
+ public function testGetMentionedUsersWithNotficationEnabled()
+ {
+ $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');
+ $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)));
+ $this->assertNotFalse($userModel->create(array('username' => 'user3.with.dot', 'notifications_enabled' => 1)));
+
+ $users = $userMentionJob->getMentionedUsers('test @user2, test, @user3.with.dot.');
+ $this->assertCount(2, $users);
+ $this->assertEquals('user2', $users[0]['username']);
+ $this->assertEquals('Foobar', $users[0]['name']);
+ $this->assertEquals('', $users[0]['email']);
+ $this->assertEquals('', $users[0]['language']);
+
+ $this->assertEquals('user3.with.dot', $users[1]['username']);
+ $this->assertEquals('', $users[1]['name']);
+ $this->assertEquals('', $users[1]['email']);
+ $this->assertEquals('', $users[1]['language']);
+ }
+
+ public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn()
+ {
+ $this->container['sessionStorage']->user = array('id' => 3);
+ $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)));
+
+ $this->assertEmpty($userMentionJob->getMentionedUsers('test @user2'));
+ }
+
+ public function testFireEventsWithMultipleMentions()
+ {
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $userModel = new UserModel($this->container);
+ $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)));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention'));
+
+ $userMentionJob->execute('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event->getAll());
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionJobTest::onUserMention', $called);
+ }
+
+ public function onUserMention($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\GenericEvent', $event);
+ $this->assertEquals(array('id' => '3', 'username' => 'user2', 'name' => 'User 2', 'email' => null, 'language' => null), $event['mention']);
+ }
+}