summaryrefslogtreecommitdiff
path: root/tests/integration/MeTest.php
blob: 21f6175612dc79d3b911d8420cddcd225b43a003 (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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php

require_once __DIR__.'/Base.php';

class MeTest extends Base
{
    public function testCreateProject()
    {
        $this->assertEquals(1, $this->app->createProject('team project'));
    }

    public function testCreateUser()
    {
        $this->assertEquals(2, $this->app->createUser('user', 'password'));
    }

    /**
     * @expectedException JsonRPC\AccessDeniedException
     */
    public function testNotAllowedAppProcedure()
    {
        $this->app->getMe();
    }

    /**
     * @expectedException JsonRPC\AccessDeniedException
     */
    public function testNotAllowedUserProcedure()
    {
        $this->user->getAllProjects();
    }

    /**
     * @expectedException JsonRPC\AccessDeniedException
     */
    public function testNotAllowedProjectForUser()
    {
        $this->user->getProjectById(1);
    }

    public function testAllowedProjectForAdmin()
    {
        $this->assertNotEmpty($this->admin->getProjectById(1));
    }

    public function testGetTimezone()
    {
        $this->assertEquals('UTC', $this->user->getTimezone());
    }

    public function testGetVersion()
    {
        $this->assertEquals('master', $this->user->getVersion());
    }

    public function testGetDefaultColor()
    {
        $this->assertEquals('yellow', $this->user->getDefaultTaskColor());
    }

    public function testGetDefaultColors()
    {
        $colors = $this->user->getDefaultTaskColors();
        $this->assertNotEmpty($colors);
        $this->assertArrayHasKey('red', $colors);
    }

    public function testGetColorList()
    {
        $colors = $this->user->getColorList();
        $this->assertNotEmpty($colors);
        $this->assertArrayHasKey('red', $colors);
        $this->assertEquals('Red', $colors['red']);
    }

    public function testGetMe()
    {
        $profile = $this->user->getMe();
        $this->assertNotEmpty($profile);
        $this->assertEquals(2, $profile['id']);
        $this->assertEquals('user', $profile['username']);
    }

    public function testCreateMyPrivateProject()
    {
        $this->assertEquals(2, $this->user->createMyPrivateProject('my project'));
    }

    public function testGetMyProjectsList()
    {
        $projects = $this->user->getMyProjectsList();
        $this->assertNotEmpty($projects);
        $this->assertArrayNotHasKey(1, $projects);
        $this->assertArrayHasKey(2, $projects);
        $this->assertEquals('my project', $projects[2]);
    }

    public function testGetMyProjects()
    {
        $projects = $this->user->getMyProjects();
        $this->assertNotEmpty($projects);
        $this->assertCount(1, $projects);
        $this->assertEquals(2, $projects[0]['id']);
        $this->assertEquals('my project', $projects[0]['name']);
        $this->assertNotEmpty($projects[0]['url']['calendar']);
        $this->assertNotEmpty($projects[0]['url']['board']);
        $this->assertNotEmpty($projects[0]['url']['list']);
    }

    public function testGetProjectById()
    {
        $project = $this->user->getProjectById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('my project', $project['name']);
        $this->assertEquals(1, $project['is_private']);
    }

    public function testCreateTask()
    {
        $this->assertEquals(1, $this->user->createTask('my user title', 2));
        $this->assertEquals(2, $this->admin->createTask('my admin title', 1));
    }

    public function testCreateTaskWithWrongMember()
    {
        $this->assertFalse($this->user->createTask(array('title' => 'something', 'project_id' => 2, 'owner_id' => 1)));
        $this->assertFalse($this->app->createTask(array('title' => 'something', 'project_id' => 1, 'owner_id' => 2)));
    }

    public function testGetTask()
    {
        $task = $this->user->getTask(1);
        $this->assertNotEmpty($task);
        $this->assertEquals('my user title', $task['title']);
        $this->assertEquals('yellow', $task['color_id']);
        $this->assertArrayHasKey('color', $task);
        $this->assertArrayHasKey('name', $task['color']);
        $this->assertArrayHasKey('border', $task['color']);
        $this->assertArrayHasKey('background', $task['color']);
    }

    /**
     * @expectedException JsonRPC\AccessDeniedException
     */
    public function testGetAdminTask()
    {
        $this->user->getTask(2);
    }

    /**
     * @expectedException JsonRPC\AccessDeniedException
     */
    public function testGetProjectActivityDenied()
    {
        $this->user->getProjectActivity(1);
    }

    public function testGetProjectActivityAllowed()
    {
        $activity = $this->user->getProjectActivity(2);
        $this->assertNotEmpty($activity);
    }

    public function testGetMyActivityStream()
    {
        $activity = $this->user->getMyActivityStream();
        $this->assertNotEmpty($activity);
    }

    public function testCloseTask()
    {
        $this->assertTrue($this->user->closeTask(1));
    }

    public function testOpenTask()
    {
        $this->assertTrue($this->user->openTask(1));
    }

    public function testMoveTaskPosition()
    {
        $this->assertTrue($this->user->moveTaskPosition(2, 1, 2, 1));
    }

    public function testUpdateTaskWithWrongMember()
    {
        $this->assertFalse($this->user->updateTask(array('id' => 1, 'title' => 'new title', 'reference' => 'test', 'owner_id' => 1)));
    }

    public function testUpdateTask()
    {
        $this->assertTrue($this->user->updateTask(array('id' => 1, 'title' => 'new title', 'reference' => 'test', 'owner_id' => 2)));
    }

    public function testGetbyReference()
    {
        $task = $this->user->getTaskByReference(2, 'test');
        $this->assertNotEmpty($task);
        $this->assertEquals('new title', $task['title']);
        $this->assertEquals(2, $task['column_id']);
        $this->assertEquals(1, $task['position']);
    }

    public function testGetMyDashboard()
    {
        $dashboard = $this->user->getMyDashboard();
        $this->assertNotEmpty($dashboard);
        $this->assertArrayHasKey('projects', $dashboard);
        $this->assertArrayHasKey('tasks', $dashboard);
        $this->assertArrayHasKey('subtasks', $dashboard);
        $this->assertNotEmpty($dashboard['projects']);
        $this->assertNotEmpty($dashboard['tasks']);
    }

    public function testGetBoard()
    {
        $this->assertNotEmpty($this->user->getBoard(2));
    }

    public function testCreateOverdueTask()
    {
        $this->assertNotFalse($this->user->createTask(array(
            'title' => 'overdue task',
            'project_id' => 2,
            'date_due' => date('Y-m-d', strtotime('-2days')),
            'owner_id' => 2,
        )));
    }

    public function testGetMyOverdueTasks()
    {
        $tasks = $this->user->getMyOverdueTasks();
        $this->assertNotEmpty($tasks);
        $this->assertCount(1, $tasks);
        $this->assertEquals('overdue task', $tasks[0]['title']);
        $this->assertEquals('my project', $tasks[0]['project_name']);
    }

    public function testGetOverdueTasksByProject()
    {
        $tasks = $this->user->getOverdueTasksByProject(2);
        $this->assertNotEmpty($tasks);
        $this->assertCount(1, $tasks);
        $this->assertEquals('overdue task', $tasks[0]['title']);
        $this->assertEquals('my project', $tasks[0]['project_name']);
    }
}