summaryrefslogtreecommitdiff
path: root/tests/units/Pagination/DashboardPaginationTest.php
blob: 6b0a40fbee81051a59c9f0e38639b723fa15116d (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
<?php

use Kanboard\Core\Security\Role;
use Kanboard\Model\ColumnModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Model\SubtaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\UserModel;
use Kanboard\Pagination\DashboardPagination;

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

class DashboardPaginationTest extends Base
{
    public function testDashboardPagination()
    {
        $projectModel = new ProjectModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);
        $taskCreationModel = new TaskCreationModel($this->container);
        $subtaskModel = new SubtaskModel($this->container);
        $dashboardPagination = new DashboardPagination($this->container);

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

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

        $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 2)));
        $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));

        $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask A', 'user_id' => 1)));
        $this->assertEquals(2, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask B', 'user_id' => 1)));
        $this->assertEquals(3, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask C')));

        $dashboard = $dashboardPagination->getOverview(1);
        $this->assertCount(1, $dashboard);
        $this->assertEquals(1, $dashboard[0]['project_id']);
        $this->assertEquals('Project #1', $dashboard[0]['project_name']);
        $this->assertEquals(1, $dashboard[0]['paginator']->getTotal());

        $tasks = $dashboard[0]['paginator']->getCollection();
        $this->assertCount(1, $tasks);
        $this->assertCount(1, $tasks[0]['subtasks']);
        $this->assertEquals('subtask B', $tasks[0]['subtasks'][0]['title']);
    }

    public function testWhenUserIsNotAssignedToTask()
    {
        $userModel = new UserModel($this->container);
        $projectModel = new ProjectModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);
        $taskCreationModel = new TaskCreationModel($this->container);
        $subtaskModel = new SubtaskModel($this->container);
        $dashboardPagination = new DashboardPagination($this->container);

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

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

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

        $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 2, 'priority' => 3)));
        $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
        $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 2, 'owner_id' => 2)));

        $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask A', 'user_id' => 2)));
        $this->assertEquals(2, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask B', 'user_id' => 1)));
        $this->assertEquals(3, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask C')));

        $dashboard = $dashboardPagination->getOverview(1);
        $this->assertCount(1, $dashboard);
        $this->assertEquals(1, $dashboard[0]['project_id']);
        $this->assertEquals('Project #1', $dashboard[0]['project_name']);
        $this->assertEquals(1, $dashboard[0]['paginator']->getTotal());

        $tasks = $dashboard[0]['paginator']->getCollection();
        $this->assertCount(1, $tasks);
        $this->assertCount(1, $tasks[0]['subtasks']);
        $this->assertEquals('subtask B', $tasks[0]['subtasks'][0]['title']);

        $dashboard = $dashboardPagination->getOverview(2);
        $this->assertCount(2, $dashboard);
        $this->assertEquals('Project #1', $dashboard[0]['project_name']);
        $this->assertEquals('Project #2', $dashboard[1]['project_name']);
        $this->assertEquals(1, $dashboard[0]['paginator']->getTotal());

        $tasks = $dashboard[0]['paginator']->getCollection();
        $this->assertCount(1, $tasks);
        $this->assertCount(0, $tasks[0]['subtasks']);

        $tasks = $dashboard[1]['paginator']->getCollection();
        $this->assertCount(2, $tasks);
        $this->assertCount(1, $tasks[0]['subtasks']);
        $this->assertEquals('subtask A', $tasks[0]['subtasks'][0]['title']);
    }

    public function testWhenColumnIsHidden()
    {
        $projectModel = new ProjectModel($this->container);
        $projectUserRoleModel = new ProjectUserRoleModel($this->container);
        $columnModel = new ColumnModel($this->container);
        $taskCreationModel = new TaskCreationModel($this->container);
        $subtaskModel = new SubtaskModel($this->container);
        $dashboardPagination = new DashboardPagination($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
        $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER));

        $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
        $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1', 'user_id' => 1)));

        $this->assertCount(1, $dashboardPagination->getOverview(1));

        $this->assertTrue($columnModel->update(1, 'test', 0, '', 1));
        $this->assertCount(0, $dashboardPagination->getOverview(1));
    }
}