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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Model\Task;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\ProjectActivity;
use Kanboard\Model\Project;
use Kanboard\Model\Subtask;
use Kanboard\Model\Comment;
use Kanboard\Model\File;
use Kanboard\Subscriber\NotificationSubscriber;
class ProjectActivityTest extends Base
{
public function testGetTitle()
{
$pa = new ProjectActivity($this->container);
$p = new Project($this->container);
$tf = new TaskFinder($this->container);
$tc = new TaskCreation($this->container);
$s = new Subtask($this->container);
$c = new Comment($this->container);
$f = new File($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
$this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
$this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
$this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
$task = $tf->getDetails(1);
$subtask = $s->getById(1, true);
$comment = $c->getById(1);
$file = $c->getById(1);
$this->assertNotEmpty($task);
$this->assertNotEmpty($subtask);
$this->assertNotEmpty($comment);
$this->assertNotEmpty($file);
foreach (NotificationSubscriber::getSubscribedEvents() as $event_name => $listeners) {
$this->assertNotEmpty($pa->getTitle(array(
'event_name' => $event_name,
'task' => $task,
'comment' => $comment,
'subtask' => $subtask,
'file' => $file,
'author' => 'bob',
'changes' => array())
));
}
}
public function testDecode()
{
$e = new ProjectActivity($this->container);
$input = array('test');
$serialized = serialize($input);
$json = json_encode($input);
$this->assertEquals($input, $e->decode($serialized));
$this->assertEquals($input, $e->decode($json));
}
public function testCreation()
{
$e = new ProjectActivity($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1)));
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
$this->assertTrue($e->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $tf->getById(2))));
$this->assertFalse($e->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $tf->getbyId(1))));
$events = $e->getProject(1);
$this->assertNotEmpty($events);
$this->assertTrue(is_array($events));
$this->assertEquals(2, count($events));
$this->assertEquals(time(), $events[0]['date_creation'], '', 1);
$this->assertEquals(Task::EVENT_UPDATE, $events[0]['event_name']);
$this->assertEquals(Task::EVENT_CLOSE, $events[1]['event_name']);
}
public function testFetchAllContent()
{
$e = new ProjectActivity($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$nb_events = 80;
for ($i = 0; $i < $nb_events; $i++) {
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_UPDATE, array('task' => $tf->getbyId(1))));
}
$events = $e->getProject(1);
$this->assertNotEmpty($events);
$this->assertTrue(is_array($events));
$this->assertEquals(50, count($events));
$this->assertEquals('admin', $events[0]['author']);
$this->assertNotEmpty($events[0]['event_title']);
$this->assertNotEmpty($events[0]['event_content']);
}
public function testCleanup()
{
$e = new ProjectActivity($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$max = 15;
$nb_events = 100;
for ($i = 0; $i < $nb_events; $i++) {
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
}
$this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count());
$e->cleanup($max);
$events = $e->getProject(1);
$this->assertNotEmpty($events);
$this->assertTrue(is_array($events));
$this->assertEquals($max, count($events));
$this->assertEquals(100, $events[0]['id']);
$this->assertEquals(99, $events[1]['id']);
$this->assertEquals(86, $events[14]['id']);
// Cleanup during task creation
$nb_events = ProjectActivity::MAX_EVENTS + 10;
for ($i = 0; $i < $nb_events; $i++) {
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
}
$this->assertEquals(ProjectActivity::MAX_EVENTS, $this->container['db']->table('project_activities')->count());
}
}
|