summaryrefslogtreecommitdiff
path: root/tests/units/TaskStatusTest.php
blob: 9b17ccd7a74ef6cab3c019507a00f1e76cfdec2c (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
<?php

require_once __DIR__.'/Base.php';

use Model\Task;
use Model\TaskFinder;
use Model\TaskStatus;
use Model\Project;
use Model\ProjectPermission;

class TaskStatusTest extends Base
{
    public function testStatus()
    {
        $t = new Task($this->container);
        $tf = new TaskFinder($this->container);
        $ts = new TaskStatus($this->container);
        $p = new Project($this->container);

        $this->assertEquals(1, $p->create(array('name' => 'test')));
        $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1)));

        // The task must be open

        $this->assertTrue($ts->isOpen(1));

        $task = $tf->getById(1);
        $this->assertNotEmpty($task);
        $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
        $this->assertEquals(0, $task['date_completed']);
        $this->assertEquals(time(), $task['date_modification']);

        // We close the task

        $ts->close(1);

        $this->assertTrue($ts->isClosed(1));

        $task = $tf->getById(1);
        $this->assertNotEmpty($task);
        $this->assertEquals(Task::STATUS_CLOSED, $task['is_active']);
        $this->assertEquals(time(), $task['date_completed']);
        $this->assertEquals(time(), $task['date_modification']);

        $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));

        // We open the task again

        $ts->open(1);

        $this->assertTrue($ts->isOpen(1));

        $task = $tf->getById(1);
        $this->assertNotEmpty($task);
        $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
        $this->assertEquals(0, $task['date_completed']);
        $this->assertEquals(time(), $task['date_modification']);

        $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_OPEN));
    }
}