1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\Comment;
use Kanboard\Model\Project;
use Kanboard\Model\ProjectUserRole;
use Kanboard\Model\User;
use Kanboard\Action\CommentCreation;
use Kanboard\Core\Security\Role;
class CommentCreationTest extends Base
{
public function testSuccess()
{
$userModel = new User($this->container);
$projectModel = new Project($this->container);
$projectUserRoleModel = new ProjectUserRole($this->container);
$commentModel = new Comment($this->container);
$taskCreationModel = new TaskCreation($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(2, $userModel->create(array('username' => 'user1')));
$this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'comment' => 'test123', 'reference' => 'ref123', 'user_id' => 2));
$action = new CommentCreation($this->container);
$action->setProjectId(1);
$action->addEvent('test.event', 'Test Event');
$this->assertTrue($action->execute($event, 'test.event'));
$comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals(1, $comment['task_id']);
$this->assertEquals('test123', $comment['comment']);
$this->assertEquals('ref123', $comment['reference']);
$this->assertEquals(2, $comment['user_id']);
}
public function testWithUserNotAssignable()
{
$userModel = new User($this->container);
$projectModel = new Project($this->container);
$projectUserRoleModel = new ProjectUserRole($this->container);
$commentModel = new Comment($this->container);
$taskCreationModel = new TaskCreation($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(2, $userModel->create(array('username' => 'user1')));
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'comment' => 'test123', 'user_id' => 2));
$action = new CommentCreation($this->container);
$action->setProjectId(1);
$action->addEvent('test.event', 'Test Event');
$this->assertTrue($action->execute($event, 'test.event'));
$comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals(1, $comment['task_id']);
$this->assertEquals('test123', $comment['comment']);
$this->assertEquals('', $comment['reference']);
$this->assertEquals(0, $comment['user_id']);
}
public function testWithNoComment()
{
$userModel = new User($this->container);
$projectModel = new Project($this->container);
$projectUserRoleModel = new ProjectUserRole($this->container);
$commentModel = new Comment($this->container);
$taskCreationModel = new TaskCreation($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(2, $userModel->create(array('username' => 'user1')));
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
$action = new CommentCreation($this->container);
$action->setProjectId(1);
$action->addEvent('test.event', 'Test Event');
$this->assertFalse($action->execute($event, 'test.event'));
}
}
|