summaryrefslogtreecommitdiff
path: root/tests/units/Model/ProjectDuplicationModelTest.php
blob: ac93d67cc12bf038ffb156151afedf59a6cf1956 (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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
<?php

require_once __DIR__.'/../Base.php';

use Kanboard\Model\ActionModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Model\ProjectGroupRoleModel;
use Kanboard\Model\ProjectDuplicationModel;
use Kanboard\Model\TagModel;
use Kanboard\Model\TaskTagModel;
use Kanboard\Model\UserModel;
use Kanboard\Model\GroupModel;
use Kanboard\Model\GroupMemberModel;
use Kanboard\Model\SwimlaneModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Core\Security\Role;

class ProjectDuplicationModelTest extends Base
{
    public function testGetSelections()
    {
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);
        $this->assertCount(7, $projectDuplicationModel->getOptionalSelection());
        $this->assertCount(10, $projectDuplicationModel->getPossibleSelection());
    }

    public function testGetClonedProjectName()
    {
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals('test (Clone)', $projectDuplicationModel->getClonedProjectName('test'));

        $this->assertEquals(50, strlen($projectDuplicationModel->getClonedProjectName(str_repeat('a', 50))));
        $this->assertEquals(str_repeat('a', 42).' (Clone)', $projectDuplicationModel->getClonedProjectName(str_repeat('a', 50)));

        $this->assertEquals(50, strlen($projectDuplicationModel->getClonedProjectName(str_repeat('a', 60))));
        $this->assertEquals(str_repeat('a', 42).' (Clone)', $projectDuplicationModel->getClonedProjectName(str_repeat('a', 60)));
    }

    public function testClonePublicProject()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Public')));
        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('Public (Clone)', $project['name']);
        $this->assertEquals(1, $project['is_active']);
        $this->assertEquals(0, $project['is_private']);
        $this->assertEquals(0, $project['is_public']);
        $this->assertEquals(0, $project['owner_id']);
        $this->assertEmpty($project['token']);
    }

    public function testClonePrivateProject()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Private', 'is_private' => 1), 1, true));
        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('Private (Clone)', $project['name']);
        $this->assertEquals(1, $project['is_active']);
        $this->assertEquals(1, $project['is_private']);
        $this->assertEquals(0, $project['is_public']);
        $this->assertEquals(0, $project['owner_id']);
        $this->assertEmpty($project['token']);

        $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
    }

    public function testCloneSharedProject()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Shared')));
        $this->assertTrue($projectModel->update(array('id' => 1, 'is_public' => 1, 'token' => 'test')));

        $project = $projectModel->getById(1);
        $this->assertEquals('test', $project['token']);
        $this->assertEquals(1, $project['is_public']);

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('Shared (Clone)', $project['name']);
        $this->assertEquals('', $project['token']);
        $this->assertEquals(0, $project['is_public']);
    }

    public function testCloneInactiveProject()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Inactive')));
        $this->assertTrue($projectModel->update(array('id' => 1, 'is_active' => 0)));

        $project = $projectModel->getById(1);
        $this->assertEquals(0, $project['is_active']);

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('Inactive (Clone)', $project['name']);
        $this->assertEquals(1, $project['is_active']);
    }

    public function testCloneProjectWithOwner()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));

        $project = $projectModel->getById(1);
        $this->assertEquals(0, $project['owner_id']);

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('Owner (Clone)', $project['name']);
        $this->assertEquals(1, $project['owner_id']);

        $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
    }

    public function testCloneProjectWithDifferentPriorities()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array(
            'name' => 'My project',
            'priority_default' => 2,
            'priority_start' => -2,
            'priority_end' => 8,
        )));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('My project (Clone)', $project['name']);
        $this->assertEquals(2, $project['priority_default']);
        $this->assertEquals(-2, $project['priority_start']);
        $this->assertEquals(8, $project['priority_end']);
    }

    public function testCloneProjectWithDifferentName()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));

        $project = $projectModel->getById(1);
        $this->assertEquals(0, $project['owner_id']);

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1, 'Foobar'));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('Foobar', $project['name']);
        $this->assertEquals(1, $project['owner_id']);
    }

    public function testCloneProjectAndForceItToBePrivate()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));

        $project = $projectModel->getById(1);
        $this->assertEquals(0, $project['owner_id']);
        $this->assertEquals(0, $project['is_private']);

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1, 'Foobar', true));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('Foobar', $project['name']);
        $this->assertEquals(1, $project['owner_id']);
        $this->assertEquals(1, $project['is_private']);
    }

    public function testCloneProjectWithCategories()
    {
        $projectModel = new ProjectModel($this->container);
        $categoryModel = new CategoryModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
        $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1)));
        $this->assertEquals(3, $categoryModel->create(array('name' => 'C3', 'project_id' => 1)));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $project = $projectModel->getById(2);
        $this->assertNotEmpty($project);
        $this->assertEquals('P1 (Clone)', $project['name']);

        $categories = $categoryModel->getAll(2);
        $this->assertCount(3, $categories);
        $this->assertEquals('C1', $categories[0]['name']);
        $this->assertEquals('C2', $categories[1]['name']);
        $this->assertEquals('C3', $categories[2]['name']);
    }

    public function testCloneProjectWithUsers()
    {
        $projectModel = new ProjectModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);
        $userModel = new UserModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
        $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
        $this->assertEquals(4, $userModel->create(array('username' => 'user3')));

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
        $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
        $this->assertTrue($projectUserRoleModel->addUser(1, 4, Role::PROJECT_VIEWER));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $this->assertCount(3, $projectUserRoleModel->getUsers(2));
        $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
        $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3));
        $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4));
    }

    public function testCloneProjectWithUsersAndOverrideOwner()
    {
        $projectModel = new ProjectModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);
        $userModel = new UserModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
        $this->assertEquals(1, $projectModel->create(array('name' => 'P1'), 2));

        $project = $projectModel->getById(1);
        $this->assertEquals(2, $project['owner_id']);

        $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
        $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1));

        $this->assertCount(2, $projectUserRoleModel->getUsers(2));
        $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
        $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));

        $project = $projectModel->getById(2);
        $this->assertEquals(1, $project['owner_id']);
    }

    public function testCloneTeamProjectToPrivatProject()
    {
        $projectModel = new ProjectModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);
        $userModel = new UserModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
        $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
        $this->assertEquals(1, $projectModel->create(array('name' => 'P1'), 2));

        $project = $projectModel->getById(1);
        $this->assertEquals(2, $project['owner_id']);
        $this->assertEquals(0, $project['is_private']);

        $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
        $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 3, 'My private project', true));

        $this->assertCount(1, $projectUserRoleModel->getUsers(2));
        $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 3));

        $project = $projectModel->getById(2);
        $this->assertEquals(3, $project['owner_id']);
        $this->assertEquals(1, $project['is_private']);
    }

    public function testCloneProjectWithGroups()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);
        $userModel = new UserModel($this->container);
        $groupModel = new GroupModel($this->container);
        $groupMemberModel = new GroupMemberModel($this->container);
        $projectGroupRoleModel = new ProjectGroupRoleModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        $this->assertEquals(1, $groupModel->create('G1'));
        $this->assertEquals(2, $groupModel->create('G2'));
        $this->assertEquals(3, $groupModel->create('G3'));

        $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
        $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
        $this->assertEquals(4, $userModel->create(array('username' => 'user3')));

        $this->assertTrue($groupMemberModel->addUser(1, 2));
        $this->assertTrue($groupMemberModel->addUser(2, 3));
        $this->assertTrue($groupMemberModel->addUser(3, 4));

        $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, Role::PROJECT_MANAGER));
        $this->assertTrue($projectGroupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER));
        $this->assertTrue($projectGroupRoleModel->addGroup(1, 3, Role::PROJECT_VIEWER));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $this->assertCount(3, $projectGroupRoleModel->getGroups(2));
        $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
        $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3));
        $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4));
    }

    public function testCloneProjectWithActionTaskAssignCurrentUser()
    {
        $projectModel = new ProjectModel($this->container);
        $actionModel = new ActionModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        $this->assertEquals(1, $actionModel->create(array(
            'project_id' => 1,
            'event_name' => TaskModel::EVENT_MOVE_COLUMN,
            'action_name' => 'TaskAssignCurrentUser',
            'params' => array('column_id' => 2),
        )));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $actions = $actionModel->getAllByProject(2);

        $this->assertNotEmpty($actions);
        $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
        $this->assertNotEmpty($actions[0]['params']);
        $this->assertEquals(6, $actions[0]['params']['column_id']);
    }

    public function testCloneProjectWithActionTaskAssignColorCategory()
    {
        $projectModel = new ProjectModel($this->container);
        $actionModel = new ActionModel($this->container);
        $categoryModel = new CategoryModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
        $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1)));
        $this->assertEquals(3, $categoryModel->create(array('name' => 'C3', 'project_id' => 1)));

        $this->assertEquals(1, $actionModel->create(array(
            'project_id' => 1,
            'event_name' => TaskModel::EVENT_CREATE_UPDATE,
            'action_name' => 'TaskAssignColorCategory',
            'params' => array('color_id' => 'blue', 'category_id' => 2),
        )));

        $this->assertEquals(2, $actionModel->create(array(
            'project_id' => 1,
            'event_name' => TaskModel::EVENT_CREATE_UPDATE,
            'action_name' => 'TaskAssignColorCategory',
            'params' => array('color_id' => 'red', 'category_id' => 0),
        )));
 
        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $actions = $actionModel->getAllByProject(2);

        $this->assertNotEmpty($actions);
        $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
        $this->assertNotEmpty($actions[0]['params']);
        $this->assertEquals('blue', $actions[0]['params']['color_id']);
        $this->assertEquals(5, $actions[0]['params']['category_id']);
        
        $this->assertEquals('TaskAssignColorCategory', $actions[1]['action_name']);
        $this->assertNotEmpty($actions[1]['params']);
        $this->assertEquals('red', $actions[1]['params']['color_id']);
        $this->assertEquals(0, $actions[1]['params']['category_id']);
    }

    public function testCloneProjectWithActionTaskAssignSpecificUser()
    {
        $projectModel = new ProjectModel($this->container);
        $actionModel = new ActionModel($this->container);
        $userModel = new UserModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
        $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
        $this->assertEquals(4, $userModel->create(array('username' => 'user3')));

        $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
        $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
        $this->assertTrue($projectUserRoleModel->addUser(1, 4, Role::PROJECT_VIEWER));

        $this->assertEquals(1, $actionModel->create(array(
            'project_id' => 1,
            'event_name' => TaskModel::EVENT_CREATE_UPDATE,
            'action_name' => 'TaskAssignSpecificUser',
            'params' => array('column_id' => 1, 'user_id' => 3),
        )));

        $this->assertEquals(2, $actionModel->create(array(
            'project_id' => 1,
            'event_name' => TaskModel::EVENT_CREATE_UPDATE,
            'action_name' => 'TaskAssignSpecificUser',
            'params' => array('column_id' => 2, 'user_id' => 0),
        )));
        
        $this->assertEquals(2, $projectDuplicationModel->duplicate(1));

        $actions = $actionModel->getAllByProject(2);

        $this->assertNotEmpty($actions);
        $this->assertEquals('TaskAssignSpecificUser', $actions[0]['action_name']);
        $this->assertNotEmpty($actions[0]['params']);
        $this->assertEquals(5, $actions[0]['params']['column_id']);
        $this->assertEquals(3, $actions[0]['params']['user_id']);

        $this->assertEquals('TaskAssignSpecificUser', $actions[1]['action_name']);
        $this->assertNotEmpty($actions[1]['params']);
        $this->assertEquals(6, $actions[1]['params']['column_id']);
        $this->assertEquals(0, $actions[1]['params']['user_id']);
    }
    
    public function testCloneProjectWithSwimlanes()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);
        $swimlaneModel = new SwimlaneModel($this->container);
        $taskCreationModel = new TaskCreationModel($this->container);
        $taskFinderModel = new TaskFinderModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        // create initial swimlanes
        $this->assertEquals(2, $swimlaneModel->create(1, 'S1'));
        $this->assertEquals(3, $swimlaneModel->create(1, 'S2'));
        $this->assertEquals(4, $swimlaneModel->create(1, 'S3'));

        // create initial tasks
        $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T0', 'project_id' => 1, 'swimlane_id' => 1)));
        $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'swimlane_id' => 2)));
        $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 3)));
        $this->assertEquals(4, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 4)));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'swimlaneModel')));

        $swimlanes = $swimlaneModel->getAll(2);
        $this->assertCount(4, $swimlanes);
        $this->assertEquals(5, $swimlanes[0]['id']);
        $this->assertEquals('Default swimlane', $swimlanes[0]['name']);
        $this->assertEquals(6, $swimlanes[1]['id']);
        $this->assertEquals('S1', $swimlanes[1]['name']);
        $this->assertEquals(7, $swimlanes[2]['id']);
        $this->assertEquals('S2', $swimlanes[2]['name']);
        $this->assertEquals(8, $swimlanes[3]['id']);
        $this->assertEquals('S3', $swimlanes[3]['name']);

        // Check if tasks are NOT been duplicated
        $this->assertCount(0, $taskFinderModel->getAll(2));
    }

    public function testCloneProjectWithTasks()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);
        $taskCreationModel = new TaskCreationModel($this->container);
        $taskFinderModel = new TaskFinderModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        // Create initial tasks
        $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1)));
        $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2)));
        $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3)));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'projectTaskDuplicationModel')));

        // Check if Tasks have been duplicated
        $tasks = $taskFinderModel->getAll(2);
        $this->assertCount(3, $tasks);
        $this->assertEquals('T1', $tasks[0]['title']);
        $this->assertEquals('T2', $tasks[1]['title']);
        $this->assertEquals('T3', $tasks[2]['title']);
    }

    public function testCloneProjectWithSwimlanesAndTasks()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);
        $swimlaneModel = new SwimlaneModel($this->container);
        $taskCreationModel = new TaskCreationModel($this->container);
        $taskFinderModel = new TaskFinderModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));

        // create initial swimlanes
        $this->assertEquals(2, $swimlaneModel->create(1, 'S1'));
        $this->assertEquals(3, $swimlaneModel->create(1, 'S2'));
        $this->assertEquals(4, $swimlaneModel->create(1, 'S3'));

        // create initial tasks
        $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
        $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
        $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'projectTaskDuplicationModel')));

        // Check if Swimlanes have been duplicated
        $swimlanes = $swimlaneModel->getAll(2);
        $this->assertCount(4, $swimlanes);
        $this->assertEquals(5, $swimlanes[0]['id']);
        $this->assertEquals('Default swimlane', $swimlanes[0]['name']);
        $this->assertEquals(6, $swimlanes[1]['id']);
        $this->assertEquals('S1', $swimlanes[1]['name']);
        $this->assertEquals(7, $swimlanes[2]['id']);
        $this->assertEquals('S2', $swimlanes[2]['name']);
        $this->assertEquals(8, $swimlanes[3]['id']);
        $this->assertEquals('S3', $swimlanes[3]['name']);

        // Check if Tasks have been duplicated
        $tasks = $taskFinderModel->getAll(2);

        $this->assertCount(3, $tasks);
        $this->assertEquals('T1', $tasks[0]['title']);
        $this->assertEquals('T2', $tasks[1]['title']);
        $this->assertEquals('T3', $tasks[2]['title']);
    }

    public function testCloneProjectWithTags()
    {
        $projectModel = new ProjectModel($this->container);
        $projectDuplicationModel = new ProjectDuplicationModel($this->container);
        $taskCreationModel = new TaskCreationModel($this->container);
        $taskFinderModel = new TaskFinderModel($this->container);
        $tagModel = new TagModel($this->container);
        $taskTagModel = new TaskTagModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
        $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'tags' => array('A'))));
        $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'tags' => array('A', 'B'))));
        $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'tags' => array('C'))));

        $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'tagDuplicationModel', 'projectTaskDuplicationModel')));

        $tasks = $taskFinderModel->getAll(2);
        $this->assertCount(3, $tasks);
        $this->assertEquals('T1', $tasks[0]['title']);
        $this->assertEquals('T2', $tasks[1]['title']);
        $this->assertEquals('T3', $tasks[2]['title']);

        $tags = $tagModel->getAllByProject(2);
        $this->assertCount(3, $tags);
        $this->assertEquals(4, $tags[0]['id']);
        $this->assertEquals('A', $tags[0]['name']);
        $this->assertEquals(5, $tags[1]['id']);
        $this->assertEquals('B', $tags[1]['name']);
        $this->assertEquals(6, $tags[2]['id']);
        $this->assertEquals('C', $tags[2]['name']);

        $tags = $taskTagModel->getList(4);
        $this->assertEquals('A', $tags[4]);

        $tags = $taskTagModel->getList(5);
        $this->assertEquals('A', $tags[4]);
        $this->assertEquals('B', $tags[5]);

        $tags = $taskTagModel->getList(6);
        $this->assertEquals('C', $tags[6]);
    }
}