summaryrefslogtreecommitdiff
path: root/tests/units/Action/CommentCreationTest.php
blob: 8a689309d909cdcb49af74b76cfdf72a140920a9 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?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\Integration\GithubWebhook;
use Kanboard\Action\CommentCreation;

class CommentCreationTest extends Base
{
    public function testWithoutRequiredParams()
    {
        $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);

        // We create a task in the first column
        $tc = new TaskCreation($this->container);
        $p = new Project($this->container);
        $c = new Comment($this->container);
        $this->assertEquals(1, $p->create(array('name' => 'test')));
        $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));

        // We create an event to move the task to the 2nd column
        $event = array(
            'project_id' => 1,
            'task_id' => 1,
            'user_id' => 1,
        );

        // Our event should be executed
        $this->assertFalse($action->execute(new GenericEvent($event)));

        $comment = $c->getById(1);
        $this->assertEmpty($comment);
    }

    public function testWithCommitMessage()
    {
        $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);

        // We create a task in the first column
        $tc = new TaskCreation($this->container);
        $p = new Project($this->container);
        $c = new Comment($this->container);
        $this->assertEquals(1, $p->create(array('name' => 'test')));
        $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));

        // We create an event to move the task to the 2nd column
        $event = array(
            'project_id' => 1,
            'task_id' => 1,
            'commit_comment' => 'plop',
        );

        // Our event should be executed
        $this->assertTrue($action->execute(new GenericEvent($event)));

        $comment = $c->getById(1);
        $this->assertNotEmpty($comment);
        $this->assertEquals(1, $comment['task_id']);
        $this->assertEquals(0, $comment['user_id']);
        $this->assertEquals('plop', $comment['comment']);
    }

    public function testWithUser()
    {
        $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);

        // We create a task in the first column
        $tc = new TaskCreation($this->container);
        $p = new Project($this->container);
        $c = new Comment($this->container);
        $this->assertEquals(1, $p->create(array('name' => 'test')));
        $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));

        // We create an event to move the task to the 2nd column
        $event = array(
            'project_id' => 1,
            'task_id' => 1,
            'user_id' => 1,
            'comment' => 'youpi',
        );

        // Our event should be executed
        $this->assertTrue($action->execute(new GenericEvent($event)));

        $comment = $c->getById(1);
        $this->assertNotEmpty($comment);
        $this->assertEquals(1, $comment['task_id']);
        $this->assertEquals(1, $comment['user_id']);
        $this->assertEquals('youpi', $comment['comment']);
    }

    public function testWithNoUser()
    {
        $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);

        // We create a task in the first column
        $tc = new TaskCreation($this->container);
        $p = new Project($this->container);
        $c = new Comment($this->container);
        $this->assertEquals(1, $p->create(array('name' => 'test')));
        $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));

        // We create an event to move the task to the 2nd column
        $event = array(
            'project_id' => 1,
            'task_id' => 1,
            'user_id' => 0,
            'comment' => 'youpi',
        );

        // Our event should be executed
        $this->assertTrue($action->execute(new GenericEvent($event)));

        $comment = $c->getById(1);
        $this->assertNotEmpty($comment);
        $this->assertEquals(1, $comment['task_id']);
        $this->assertEquals(0, $comment['user_id']);
        $this->assertEquals('youpi', $comment['comment']);
    }
}