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

require_once __DIR__.'/Base.php';

use Model\Task;
use Model\TaskFinder;
use Model\Project;
use Model\Category;
use Model\User;

class CategoryTest extends Base
{
    public function testCreation()
    {
        $t = new Task($this->container);
        $tf = new TaskFinder($this->container);
        $p = new Project($this->container);
        $c = new Category($this->container);

        $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
        $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
        $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1)));
        $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));

        $task = $tf->getById(1);
        $this->assertTrue(is_array($task));
        $this->assertEquals(2, $task['category_id']);

        $category = $c->getById(2);
        $this->assertTrue(is_array($category));
        $this->assertEquals(2, $category['id']);
        $this->assertEquals('Category #2', $category['name']);
        $this->assertEquals(1, $category['project_id']);
    }

    public function testRemove()
    {
        $t = new Task($this->container);
        $tf = new TaskFinder($this->container);
        $p = new Project($this->container);
        $c = new Category($this->container);

        $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
        $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
        $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1)));
        $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));

        $task = $tf->getById(1);
        $this->assertTrue(is_array($task));
        $this->assertEquals(2, $task['category_id']);

        $this->assertTrue($c->remove(1));
        $this->assertTrue($c->remove(2));

        // Make sure tasks assigned with that category are reseted
        $task = $tf->getById(1);
        $this->assertTrue(is_array($task));
        $this->assertEquals(0, $task['category_id']);
    }
}