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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Model\UserModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\UserNotificationFilterModel;
use Kanboard\Model\UserNotificationModel;
class UserNotificationFilterTest extends Base
{
public function testGetFilters()
{
$nf = new UserNotificationFilterModel($this->container);
$filters = $nf->getFilters();
$this->assertArrayHasKey(UserNotificationFilterModel::FILTER_NONE, $filters);
$this->assertArrayHasKey(UserNotificationFilterModel::FILTER_BOTH, $filters);
$this->assertArrayHasKey(UserNotificationFilterModel::FILTER_CREATOR, $filters);
$this->assertArrayHasKey(UserNotificationFilterModel::FILTER_ASSIGNEE, $filters);
}
public function testSaveProjectFilter()
{
$nf = new UserNotificationFilterModel($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
$this->assertEquals(3, $p->create(array('name' => 'UnitTest3')));
$this->assertEmpty($nf->getSelectedProjects(1));
$this->assertTrue($nf->saveSelectedProjects(1, array(1, 2, 3)));
$this->assertEquals(array(1, 2, 3), $nf->getSelectedProjects(1));
}
public function testSaveUserFilter()
{
$nf = new UserNotificationFilterModel($this->container);
$this->assertEquals(UserNotificationFilterModel::FILTER_BOTH, $nf->getSelectedFilter(1));
$nf->saveFilter(1, UserNotificationFilterModel::FILTER_CREATOR);
$this->assertEquals(UserNotificationFilterModel::FILTER_CREATOR, $nf->getSelectedFilter(1));
}
public function testFilterNone()
{
$u = new UserModel($this->container);
$n = new UserNotificationFilterModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE)));
$this->assertTrue($n->filterNone($u->getById(2)));
$this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH)));
$this->assertFalse($n->filterNone($u->getById(3)));
}
public function testFilterCreator()
{
$u = new UserModel($this->container);
$n = new UserNotificationFilterModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR)));
$this->assertTrue($n->filterCreator($u->getById(2), array('task' => array('creator_id' => 2))));
$this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR)));
$this->assertFalse($n->filterCreator($u->getById(3), array('task' => array('creator_id' => 1))));
$this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE)));
$this->assertFalse($n->filterCreator($u->getById(4), array('task' => array('creator_id' => 2))));
}
public function testFilterAssignee()
{
$u = new UserModel($this->container);
$n = new UserNotificationFilterModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE)));
$this->assertTrue($n->filterAssignee($u->getById(2), array('task' => array('owner_id' => 2))));
$this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE)));
$this->assertFalse($n->filterAssignee($u->getById(3), array('task' => array('owner_id' => 1))));
$this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE)));
$this->assertFalse($n->filterAssignee($u->getById(4), array('task' => array('owner_id' => 2))));
}
public function testFilterBoth()
{
$u = new UserModel($this->container);
$n = new UserNotificationFilterModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH)));
$this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
$this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 0, 'creator_id' => 2))));
$this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH)));
$this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 1, 'creator_id' => 1))));
$this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
$this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE)));
$this->assertFalse($n->filterBoth($u->getById(4), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
}
public function testFilterProject()
{
$u = new UserModel($this->container);
$n = new UserNotificationModel($this->container);
$nf = new UserNotificationFilterModel($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
// No project selected
$this->assertTrue($nf->filterProject($u->getById(1), array()));
// User that select only some projects
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE)));
$n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true)));
$this->assertFalse($nf->filterProject($u->getById(2), array('task' => array('project_id' => 1))));
$this->assertTrue($nf->filterProject($u->getById(2), array('task' => array('project_id' => 2))));
}
public function testFilterUserWithNoFilter()
{
$u = new UserModel($this->container);
$n = new UserNotificationFilterModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE)));
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1))));
}
public function testFilterUserWithAssigneeFilter()
{
$u = new UserModel($this->container);
$n = new UserNotificationFilterModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE)));
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 2))));
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 1))));
}
public function testFilterUserWithCreatorFilter()
{
$u = new UserModel($this->container);
$n = new UserNotificationFilterModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR)));
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2))));
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 1))));
}
public function testFilterUserWithBothFilter()
{
$u = new UserModel($this->container);
$n = new UserNotificationFilterModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH)));
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3))));
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2))));
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 4, 'owner_id' => 1))));
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 5, 'owner_id' => 0))));
}
public function testFilterUserWithBothFilterAndProjectSelected()
{
$u = new UserModel($this->container);
$n = new UserNotificationModel($this->container);
$nf = new UserNotificationFilterModel($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH)));
$n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true)));
$this->assertFalse($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3))));
$this->assertFalse($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2))));
$this->assertTrue($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 2, 'owner_id' => 3))));
$this->assertTrue($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 0, 'owner_id' => 2))));
}
}
|