summaryrefslogtreecommitdiff
path: root/tests/units/Analytic/TaskDistributionAnalyticTest.php
blob: 0d600b8b6da42ca6b65c7a56b673f23e3b5bc02f (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
<?php

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

use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Analytic\TaskDistributionAnalytic;

class TaskDistributionAnalyticTest extends Base
{
    public function testBuild()
    {
        $projectModel = new ProjectModel($this->container);
        $taskDistributionModel = new TaskDistributionAnalytic($this->container);

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

        $this->createTasks(1, 20, 1);
        $this->createTasks(2, 30, 1);
        $this->createTasks(3, 40, 1);
        $this->createTasks(4, 10, 1);

        $expected = array(
            array(
                'column_title' => 'Backlog',
                'nb_tasks' => 20,
                'percentage' => 20.0,
            ),
            array(
                'column_title' => 'Ready',
                'nb_tasks' => 30,
                'percentage' => 30.0,
            ),
            array(
                'column_title' => 'Work in progress',
                'nb_tasks' => 40,
                'percentage' => 40.0,
            ),
            array(
                'column_title' => 'Done',
                'nb_tasks' => 10,
                'percentage' => 10.0,
            )
        );

        $this->assertEquals($expected, $taskDistributionModel->build(1));
    }

    private function createTasks($column_id, $nb_active, $nb_inactive)
    {
        $taskCreationModel = new TaskCreationModel($this->container);

        for ($i = 0; $i < $nb_active; $i++) {
            $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'is_active' => 1)));
        }

        for ($i = 0; $i < $nb_inactive; $i++) {
            $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'is_active' => 0)));
        }
    }
}