summaryrefslogtreecommitdiff
path: root/tests/units/Model/TaskTest.php
blob: 37c68a78366f9e81420532e30edc02877f6792a1 (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
<?php

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

use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\TaskStatus;
use Model\Project;
use Model\ProjectPermission;
use Model\Category;
use Model\User;

class TaskTest extends Base
{
    public function testRemove()
    {
        $t = new Task($this->container);
        $tc = new TaskCreation($this->container);
        $tf = new TaskFinder($this->container);
        $p = new Project($this->container);

        $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
        $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));

        $this->assertTrue($t->remove(1));
        $this->assertFalse($t->remove(1234));
    }

    public function testGetTaskIdFromText()
    {
        $t = new Task($this->container);
        $this->assertEquals(123, $t->getTaskIdFromText('My task #123'));
        $this->assertEquals(0, $t->getTaskIdFromText('My task 123'));
    }

    public function testRecurrenceSettings()
    {
        $t = new Task($this->container);

        $statuses = $t->getRecurrenceStatusList();
        $this->assertCount(2, $statuses);
        $this->assertArrayHasKey(Task::RECURRING_STATUS_NONE, $statuses);
        $this->assertArrayHasKey(Task::RECURRING_STATUS_PENDING, $statuses);
        $this->assertArrayNotHasKey(Task::RECURRING_STATUS_PROCESSED, $statuses);

        $triggers = $t->getRecurrenceTriggerList();
        $this->assertCount(3, $triggers);
        $this->assertArrayHasKey(Task::RECURRING_TRIGGER_FIRST_COLUMN, $triggers);
        $this->assertArrayHasKey(Task::RECURRING_TRIGGER_LAST_COLUMN, $triggers);
        $this->assertArrayHasKey(Task::RECURRING_TRIGGER_CLOSE, $triggers);

        $dates = $t->getRecurrenceBasedateList();
        $this->assertCount(2, $dates);
        $this->assertArrayHasKey(Task::RECURRING_BASEDATE_DUEDATE, $dates);
        $this->assertArrayHasKey(Task::RECURRING_BASEDATE_TRIGGERDATE, $dates);

        $timeframes = $t->getRecurrenceTimeframeList();
        $this->assertCount(3, $timeframes);
        $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_DAYS, $timeframes);
        $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_MONTHS, $timeframes);
        $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_YEARS, $timeframes);
    }
}